Healing script doesn't work

Theres no error in the output but it just doesn’t heal

Cilent code:

local player = game.Players.LocalPlayer

player.Character.Humanoid.HealthChanged:Connect(function()

local Humanoid = player.Character.Humanoid

wait(7.5)

game.ReplicatedStorage.Heal:FireServer()

end)

Server Code:

local maxhp = 100
game.ReplicatedStorage.Heal.OnServerEvent:Connect(function(plr)
	local Humanoid = plr.Character.Humanoid
	repeat
		Humanoid.Health += 2
		wait(0.5)
	until Humanoid.Health >= maxhp
end)
2 Likes

Basically it’s a client-server problem. The player’s health is most likely changing on the client, but it hasn’t changed on the server. I’d recommend whatever is draining the player’s health, it should be done on the server rather than the client to make this script work. You can even eliminate the remote event and local script all together. None the less, all your code is working fine and doing everything it says it’s doing.

2 Likes

instead of set a maxhp from a variable, get the max health from the Maxhealth property of the humanoid.

In your client script, check if the event is fired using print(“Event fired !”)

make sure the health is decreasing when HealhChanged fired, because don’t checking this will increase the player health faster

it is better to do this using only one server script, because, players using exploits can abuse the RemoteEvent.

i mean you can use a script instead local just put a script in the starterCharacter then write in this:


local Humanoid = script.Parent.Humanoid
local currentHealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function(health)
if health < currentHealth then
repeat
		Humanoid.Health += 2
		wait(0.5)
	until Humanoid.Health >= 100
end
end)