Why is the player not being healed up? [Remote Events]

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

Has your humanoid’s Health previously taken damage before or still has full health?

Having edited the code to this:

wait(0.1)

local timeRemaining = 16
local character = script.Parent

repeat
    character.Humanoid.Health = character.Humanoid.Health + 2.5
    print(""..script.Parent.Name.." has been healed +2.5, his health is now: "..character.Humanoid.Health.." HP")
    wait(0.2)
    timeRemaining = timeRemaining - 1
    print("Healing time remain: " .. timeRemaining)
until timeRemaining == 0

script:Destroy()

The code prints:
excellentAnarchy has been healed +2.5, his health is now: 100 HP

Even though, my HP is not 100, where have I gone wrong?

I change the health manually to a number below 100, for testing.

Is that script you deduct the health from a local script or a server script?

Guess what, things have magically started working and the player is now being healed, with absolutely no changes made to any scripts.

Thank you for your time :wink:

1 Like