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

Help with health giver?

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

✓ Accepted answer

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.

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