这是剧本。我不知道为什么,但它只运行一次。
local players = game:GetService("Players")
local localplayer = players.LocalPlayer
local char = localplayer.Character
local hum = char:WaitForChild("Humanoid")
local cam = game.Workspace.CurrentCamera
local MenuCamera = game.Workspace.MenuRoom.MenuCamera
hum.Died:Connect(function()
wait(1.5)
script.Parent.DeathScreen.Visible = true
repeat
cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
cam.CFrame = MenuCamera.CFrame
wait(2)
script.Parent.DeathScreen.Visible = false
end)
我死后它只是不运行脚本。
尝试使用此代码而不是该代码,不需要重复循环,但您可以添加检查以确保代码在可以运行的时间运行。
local players = game:GetService("Players")
local localplayer = players.LocalPlayer
local char = localplayer.Character or localplayer.CharacterAdded:Wait() -- Handle character respawn
local hum = char:WaitForChild("Humanoid")
local cam = game.Workspace.CurrentCamera
local MenuCamera = game.Workspace.MenuRoom.MenuCamera
hum.Died:Connect(function()
print("Death event triggered!") -- Debugging
wait(1.5)
script.Parent.DeathScreen.Visible = true
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = MenuCamera.CFrame
wait(2)
script.Parent.DeathScreen.Visible = false
end)