Healing tool damaging the player after healing

Hello there,

i have a tool in my game that is meant to heal the player when activated, sadly some sort of glitch keeps happening with no errors in the output. Basically, it heals the player and then damages them again?

here is my current code, a local script within the tool

local water = script.Parent
local healingAmount = 30
local equipped = false
local plr = game.Players.LocalPlayer
local char = plr.Character

water.Equipped:Connect(function()
	equipped = true
end)

water.Unequipped:Connect(function()
	equipped = false
end)

water.Activated:Connect(function()
local hum = char:WaitForChild("Humanoid")
if hum.Health < 100 then
		hum.Health = hum.Health + healingAmount
	water:Destroy()
	end
end)
2 Likes

You are manipulating Humanoid properties on the client instead of the server, meaning only the player will see the changes. Change it into a server script and use this instead:

local water = script.Parent
local healingAmount = 30

water.Activated:Connect(function()
    local character = water.Parent
    local humanoid = if character then character:FindFirstChildOfClass("Humanoid") else nil

    if humanoid ~= nil and humanoid.Health < humanoid.MaxHealth then
        humanoid.Health += healingAmount
        water:Destroy()
    end
end)
1 Like

thank you so much! i’ll test it right now, this looks right though.

yep, it works exactly as intended! thanks for answering even though this was kind of a dumb question in hindsight

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.