我决定使用自定义健康,而不是依赖于人形机器人的健康。新的生命值是通过值来衡量的,而且效果很好,我想让角色冻结几秒钟,然后将它们传送到一个特定的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这个脚本一般都不起作用。即使当它被启用并放在正确的位置时,它也从未工作过。
发布于 2018-12-30 21:21:53
如果我没理解错的话,你想要传送角色到一个位置,当它的生命值在冻结几秒钟后达到低于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)发布于 2019-01-23 20:50:08
以下是一些修复,如果这是服务器脚本,则更改为:
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
https://stackoverflow.com/questions/53935987
复制相似问题