基本上,我正在制作一个脚本,该脚本在某个人死亡时打印“ played dead”,而当该人死亡时,该脚本停止工作。来源:
local hum = game:GetService("Players").LocalPlayer.Character.Humanoid
hum.HealthChanged:connect(function(health)
if (health == 0) then
print("player died!")
end
end)
该脚本只能运行一次,当角色重生时如何使它再次运行?
答案 0 :(得分:0)
Roblox的Humanoid类有一个“死亡”事件,请问您为什么不使用它?每当人形生物被斩首或生命值直接设置为0时,它就会触发。
根据您的使用情况,我会亲自尝试:
hum.Died:connect(function()
print("A player has died!");
end)
他们在网站上提供的脚本示例显示了玩家的名字和死亡消息,如下所示:
game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
print(player.Name .. " has died!")
end)
end)
end)
以下一些链接可能对您有用:
http://wiki.roblox.com/index.php?title=API:Class_reference
http://wiki.roblox.com/index.php?title=API:Class/Humanoid
http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Died