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)
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)