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

Why when I click it on low health I don't heal?

local HealAmmount = 30
local HealButton = script.Parent

function ClickToHeal(hit)
	local character = hit.Parent
	local Humanoid = character:FindFirstChild("Humanoid")
	if Humanoid then 
		local currentHealth = Humanoid.Health
		local newHealth = currentHealth + HealAmmount
	end
end

HealButton.ClickDetector.MouseClick:connect(ClickToHeal)

2 answers

✓ Accepted answer

If you take a look at the documentation for the MouseClick event you can see that it is documented as.

RBXScriptSignal MouseClick (
   Player playerWhoClicked
)

This means that the event will return the player that clicked it (not a body part like the Touched event). We can use that to change your script around a little bit.

-- ... the rest of your script
function ClickToHeal(player)
    local character = player.Character
    if character then
        local Humanoid = character:FindFirstChild("Humanoid")
        local currentHealth = Humanoid.Health
        local newHealth = currentHealth + HealAmmount
     end
end

HealButton.ClickDetector.MouseClick:connect(ClickToHeal)

Now we get the player that clicked, check that they have a character (sometimes they don't), and then we change the humanoid around (I don't think then we have to check for it).

you arent setting the humanoid's health property, yu are just making a variable to set the health property, do

Humanoid.Health = newHealth

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