Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
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)

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?

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

Ad
Log in to vote
0
Answered by 7 years ago

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

Humanoid.Health = newHealth