ROBLOX。所以,这个函数只运行一次,我不知道为什么。有谁知道为什么吗?

问题描述 投票:0回答:1

这是剧本。我不知道为什么,但它只运行一次。

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)

我死后它只是不运行脚本。

lua roblox
1个回答
0
投票

尝试使用此代码而不是该代码,不需要重复循环,但您可以添加检查以确保代码在可以运行的时间运行。

    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)
© www.soinside.com 2019 - 2024. All rights reserved.