【问题标题】:Roblox Lua | If character respawns, script stops working ( HealthChanged )Roblox Lua |如果角色重生,脚本将停止工作( HealthChanged )
【发布时间】:2018-07-01 23:58:00
【问题描述】:

基本上,我正在制作一个脚本,当某人死亡时打印“played dead”,但当此人死亡时,脚本停止工作。这是来源:

local hum = game:GetService("Players").LocalPlayer.Character.Humanoid

hum.HealthChanged:connect(function(health)
if (health == 0) then
print("player died!")
end
end)

脚本只能运行一次,如何在角色重生时再次运行?

【问题讨论】:

    标签: lua roblox


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 2020-07-02
      • 1970-01-01
      • 2016-02-04
      • 2016-03-31
      • 1970-01-01
      • 2022-10-20
      • 2022-07-12
      • 2020-11-21
      • 2020-06-23
      相关资源
      最近更新 更多