首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >低NumberValue对脚本不起任何作用

低NumberValue对脚本不起任何作用
EN

Stack Overflow用户
提问于 2018-12-27 02:56:32
回答 2查看 47关注 0票数 0

我决定使用自定义健康,而不是依赖于人形机器人的健康。新的生命值是通过值来衡量的,而且效果很好,我想让角色冻结几秒钟,然后将它们传送到一个特定的Vector3值。

我试着用不同的方式编写脚本,但所有的脚本都不起作用。我甚至试着把它弄到球员的位置不同的地方,但也失败了。

代码语言:javascript
运行
复制
--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

这个脚本一般都不起作用。即使当它被启用并放在正确的位置时,它也从未工作过。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-30 21:21:53

如果我没理解错的话,你想要传送角色到一个位置,当它的生命值在冻结几秒钟后达到低于30的值。然后,您应该在每次PlayerHealth的值发生变化时检查它,方法是将它连接到一个函数,以捕捉它降到30以下的时刻:

代码语言:javascript
运行
复制
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)
票数 0
EN

Stack Overflow用户

发布于 2019-01-23 20:50:08

以下是一些修复,如果这是服务器脚本,则更改为:

代码语言:javascript
运行
复制
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)

否则,如果它是一个本地脚本,那么只需更改以下内容

代码语言:javascript
运行
复制
local Player = game.Players:GetPlayerFromCharacter(Figure)

代码语言:javascript
运行
复制
local Player = game.Players.LocalPlayer

希望它起作用了,不要忘记选择它作为正确的答案,并请喜欢它=D

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53935987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档