【问题标题】:Low NumberValue does nothing for the script低 NumberValue 对脚本没有任何作用
【发布时间】:2019-05-24 22:45:42
【问题描述】:

我决定不依赖 Humanoid 的生命值,而是使用自定义生命值。新的生命值按值计算并且效果很好,我想让角色冻结几秒钟,然后将它们传送到特定的 Vector3 值。

我尝试以不同的方式编写脚本,但它们都不起作用。我什至试图把它放到玩家位置不同的地方,但也失败了。

--Responsible for healing a player's humanoid's health

-- declarations
local Figure = script.Parent
local Head = Figure:WaitForChild("Head")
local Humanoid = Figure:WaitForChild("Humanoid")
local PlayerHealth = game.Players.LocalPlayer.Character.Data.Health
local Player = game.Players.LocalPlayer.Character.Humanoid



if PlayerHealth.Value < 30 then
    Player.WalkSpeed = 0
    wait(5)
    Player.WalkSpeed = 16
end

该脚本通常无法正常工作。即使启用并放置在正确的位置,它也无法正常工作。

【问题讨论】:

    标签: lua scripting roblox


    【解决方案1】:

    这里有一些修复,如果这是一个服务器脚本,那么改成这个:

    local Figure = script.Parent
    local Head = Figure:WaitForChild("Head")
    local Humanoid = Figure:WaitForChild("Humanoid")
    local Player = game.Players:GetPlayerFromCharacter(Figure) --It will get the player from his character as server scripts can't access LocalPlayer
    local Health = Player:WaitForChild("Data"):WaitForChild("Health")
    
    
    Health.Changed:Connect(function()
        if Health.Value < 30 then
            Player.WalkSpeed = 0
            wait(5)
            -- Add more code here
            Player.WalkSpeed = 16
        end
    end)
    

    如果它是本地脚本,则只需更改它

    local Player = game.Players:GetPlayerFromCharacter(Figure)
    

    local Player = game.Players.LocalPlayer
    

    希望它成功了,不要忘记选择它作为正确答案,请喜欢它=D

    【讨论】:

      【解决方案2】:

      如果我理解正确的话,你想将角色传送到一个位置,当它冻结几秒钟后,它的生命值低于 30 时。然后你应该检查 PlayerHealth 的值,每次它的值发生变化时,通过将它连接到一个函数来捕捉它的生命值低于 30 的时刻:

      local Figure = script.Parent
      local Head = Figure:WaitForChild("Head")
      local Humanoid = Figure:WaitForChild("Humanoid")
      local Data = Figure:WaitForChild("Data") --In any case if the data loads after the script runs
      local PlayerHealth = game.Players.LocalPlayer.Character.Data.Health
      local Player = game.Players.LocalPlayer.Character.Humanoid
      
      
      PlayerHealth.Changed:connect(function()--Here you check the value every time it changes.
      if PlayerHealth.Value < 30 then
          Player.WalkSpeed = 0
          wait(5)
          -- you can add teleportation here.
          --Figure:MoveTo(Position)
          Player.WalkSpeed = 16
      end
      end)
      

      【讨论】:

        猜你喜欢
        • 2013-11-01
        • 1970-01-01
        • 2023-03-30
        • 1970-01-01
        • 2021-05-09
        • 2019-06-23
        • 2019-11-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多