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

Help with health giver?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

I made a script where when you click a part (First aid kit), it gives you +30 health. For some reason even when I have 100 health, I am able to still buy it. I only want when you have lower than 30 health you can buy it (that's so the players don't buy if they have full health).

script.Parent.ClickDetector.MouseClick:connect(function(Clicker)
    Clicker = Clicker.Character 
    if Clicker.Humanoid.Health <= 100 then
        Clicker.Humanoid.Health = Clicker.Humanoid.Health + 30 
        for i,v in pairs {script.Parent.Parent} do
            local Storage = game:GetService("ServerStorage"):WaitForChild("MedKitsStorage")
            v.Parent = Storage
            wait(60)
            v.Parent = game.Workspace:WaitForChild("Storage")
        end
    end
end)

1 answer

Log in to vote
2
Answered by 8 years ago

On line 3 of your script instead of it being

if Clicker.Humanoid.Health <= 100 then

Change it to:

if Clicker.Humanoid.Health <= 30 then

What you were doing before allows the player to buy the first aid kit because it's saying "if health is less than or equal to 100" So no matter what your health is it will allow the player to purchase the first aid kit. It's a simple fix, just make sure it's saying "if health is less than or equal to 30". That will only allow the player to buy the first aid kit if their health is 30 or less than that.

Ad

Answer this question