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)
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
Closed as Non-Descriptive by hiimgoodpack and Goulstem
This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.
Why was this question closed?