Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is the player not being healed? [Remote Event]

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.

Thank you, excA


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.


```edit#2

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?

2 comments

0

what does it print

0

It prints "print("Healing time remain: " .. timeRemaining)" every 0.2, therefore the code works.

2 answers

I believe the problem here is that when you clone the script and make disabled false, the variables are already initialized, so the character isn't actually initialized as script.Parent.

To fix this, only set HealScript.Disabled = false after it has been parented.

1 comment

0

Hey, thank you for the answer, however I do already have that line in the code. The script works, as it does print "print("Healing time remain: " .. timeRemaining)" every 0.2 of a second. However the health isn't added with each loop.

Things have started magically working perfectly with no changes made to the scripts. Thanks to everyone for their time :)

This discussion is preserved as it was. New answers, comments, and votes are closed.