The script below is being inserted into a Player’s Character through a Remote Event.
wait(0.1)
local character = script.Parent
local timeRemaining = 16
repeat
character.Humanoid.Health = character.Humanoid.Health + 2.5
wait(0.2)
timeRemaining = timeRemaining - 1
print("Healing time remain: " .. timeRemaining)
until timeRemaining == 0
script:Destroy()
It’s a simple script, and does not seem to have any issues running as it prints 16 times, every 0.2 seconds. However there is no effect on the Health. It’s not healing the player by 2.5 every 0.2 x 16.
Does anyone know the issue? I have also tried using a while true loop, simply doing character.Humanoid.Health + 30, etc. with no luck.
I’m attaching the code responsible for moving the above script to Character too:
local RemoteEvents = game:GetService("ReplicatedStorage").Events
local HealOthers = RemoteEvents.HealOthers
local function onHealOthers(player)
print(player.Name, "heals up others")
local HealScript = script.HealScript:Clone()
local character = player.Character
HealScript.Parent = character
HealScript.Disabled = false
for i, v in pairs(game.Players:GetPlayers()) do
if (v.Character.HumanoidRootPart.Position - character.HumanoidRootPart.Position).magnitude <= (15) then
if v.Team == player.Team then
print(v.Name.." has been healed up")
HealScript.Parent = v.Character
HealScript.Disabled = false
end
end
end
end
HealOthers.OnServerEvent:Connect(onHealOthers)
It also works, as the script is copied and parented to the Character.
Thanks,
excA