为什么类人生物的健康状况没有改变?
Why isn't humanoid health changing?
所以我正在制作一个脚本来治疗玩家一定量,但生命值根本没有改变。我知道代码正在执行,因为我可以通过 print 语句看到输出,但是出于某种原因 print 语句总是读取 100。我试过禁用健康再生脚本,但似乎也没有用。
(在工具中的脚本中)
local Medkit = script.Parent
Medkit.RemoteEvent.OnServerEvent:Connect(function()
local Player = Medkit.Parent
print(Player.Humanoid.Health)
if Player.Humanoid.Health <= Player.Humanoid.MaxHealth - 50 then --Change the number to the healing power mentioned below
Player.Humanoid.Health = Player.Humanoid.Health + 50 --This number determines the healing power
else
Player.Humanoid.Health = Player.Humanoid.MaxHealth
end
end)
(不要评判我的剧本,我比较新)
编辑:我试过 Humanoid:TakeDamage()
设置为负值,但没有用。它窃听了健康系统并将其设置为超过 MaxHealth 的值。
EDIT2:我在我的逻辑中包含了一些打印语句。
我已经按照您的要求在逻辑中包含了打印语句。
local Medkit = script.Parent
Medkit.RemoteEvent.OnServerEvent:Connect(function()
local Player = Medkit.Parent
print(Player.Humanoid.Health)
if Player.Humanoid.Health <= Player.Humanoid.MaxHealth - 50 then --Change the number to the healing power mentioned below
Player.Humanoid.Health = Player.Humanoid.Health + 50 --This number determines the healing power
print("added 50")
else
Player.Humanoid.Health = Player.Humanoid.MaxHealth
print("set 50")
end
end)
我测试这个脚本的方法是通过浏览器手动设置 Player.Humanoid.Health
值。我已经测试过```播放器。 Humanoid.Health```` = 60、50、40 和 30,但都产生了相同的输出;
100
set 50
即使 Player.Humanoid.Health
以某种方式读取 100,它仍会将值设置为 100。
EDIT3:我测试了 Player.Humanoid.MaxHealth
的不同值,它是 150
,因此 Player.Humanoid.Health
也是 150
。但是,代码仍然打印:
100
set 50
EDIT4:打印 Player.Humanoid.MaxHealth
.
时发生了 EDIT3 中提到的相同事情
我找到原因了。
不是工具坏了,而是我用来测试它的方法。我在本地测试了它,由于 filtering = enabled
,它没有在服务器上更新它,因此健康状况没有改变。
谢谢大家的帮助,你们引导我找到了解决这个问题的正确途径。
所以我正在制作一个脚本来治疗玩家一定量,但生命值根本没有改变。我知道代码正在执行,因为我可以通过 print 语句看到输出,但是出于某种原因 print 语句总是读取 100。我试过禁用健康再生脚本,但似乎也没有用。
(在工具中的脚本中)
local Medkit = script.Parent
Medkit.RemoteEvent.OnServerEvent:Connect(function()
local Player = Medkit.Parent
print(Player.Humanoid.Health)
if Player.Humanoid.Health <= Player.Humanoid.MaxHealth - 50 then --Change the number to the healing power mentioned below
Player.Humanoid.Health = Player.Humanoid.Health + 50 --This number determines the healing power
else
Player.Humanoid.Health = Player.Humanoid.MaxHealth
end
end)
(不要评判我的剧本,我比较新)
编辑:我试过 Humanoid:TakeDamage()
设置为负值,但没有用。它窃听了健康系统并将其设置为超过 MaxHealth 的值。
EDIT2:我在我的逻辑中包含了一些打印语句。 我已经按照您的要求在逻辑中包含了打印语句。
local Medkit = script.Parent
Medkit.RemoteEvent.OnServerEvent:Connect(function()
local Player = Medkit.Parent
print(Player.Humanoid.Health)
if Player.Humanoid.Health <= Player.Humanoid.MaxHealth - 50 then --Change the number to the healing power mentioned below
Player.Humanoid.Health = Player.Humanoid.Health + 50 --This number determines the healing power
print("added 50")
else
Player.Humanoid.Health = Player.Humanoid.MaxHealth
print("set 50")
end
end)
我测试这个脚本的方法是通过浏览器手动设置 Player.Humanoid.Health
值。我已经测试过```播放器。 Humanoid.Health```` = 60、50、40 和 30,但都产生了相同的输出;
100
set 50
即使 Player.Humanoid.Health
以某种方式读取 100,它仍会将值设置为 100。
EDIT3:我测试了 Player.Humanoid.MaxHealth
的不同值,它是 150
,因此 Player.Humanoid.Health
也是 150
。但是,代码仍然打印:
100
set 50
EDIT4:打印 Player.Humanoid.MaxHealth
.
我找到原因了。
不是工具坏了,而是我用来测试它的方法。我在本地测试了它,由于 filtering = enabled
,它没有在服务器上更新它,因此健康状况没有改变。
谢谢大家的帮助,你们引导我找到了解决这个问题的正确途径。