为什么我的脚本只在我的 humanoid/noob 上运行一次?

以下是我的代码:

game.Workspace.Demons_Boss.Humanoid.Died:connect(function()
for i, v in pairs(game.Players:GetChildren()) do
v.PlayerGui.ScreenGui.MagesWin.Visible = true
v.PlayerGui.ScreenGui.DemonsWin.Visible = false
v.PlayerGui.SreenGui.MagesWin.LocalScript.Disabled = false
end
end)

我知道我的代码只运行一次,因为我尝试打印一些东西,结果只在输出中运行了一次。在 humanoid/noob 模型中,我还添加了一个 regen 脚本。如果需要我的 regen 脚本,如下所示:

name = "Humanoid"

robo = script.Parent:Clone()

While true do
wait(3)
if script.Parent.Humanoid.Health <1 then
robot = robo:Clone()
robot.Parent = script.Parent.Parent
robot:MakeJoints()
script.Parent:remove()
wait(7)
local p = game.Players:GetChildren()
for i = 1,#p do
p[i].Character.Head:remove()
end
end
end

这两个脚本都在两个不同的脚本中。

我真的需要帮助,因为我已经搜索了1个月的错误。

谢谢!

点赞
用户9395934
用户9395934

game.Workspace之后,你应该使用 . 代替 **,**。如果人形角色死亡且其角色被删除,则该事件将被断开连接。

2018-05-25 18:31:54
用户9808476
用户9808476

你的代码中有一个打字错误。在第1行,你输入了逗号而不是点号:

game.Workspace,Demons_Boss.Humanoid.Died:connect(function()

你应该用以下内容替换该行:

workspace["Demons_Boss"].Humanoid.Died:connect(function()

请注意,“workspace” 等同于 “game.Workspace”。

2018-05-27 17:02:29
用户8807908
用户8807908

一种替代方案是:

game.Workspace,Demons_Boss.Humanoid.Died:connect(function()

应该改为

game.Workspace["Demons_Boss"].Humanoid.Died:connect(function()
2018-05-31 21:09:29