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

Help with if statement?

I made this script where if you press on a part, you get +5 health. But I would like a if statement to be like, if the player has 100 health then he is not able to get it. Idk how to add that. Any help is appreciated.

script.Parent.ClickDetector.MouseClick:connect(function(Clicker)
	Clicker = Clicker.Character 
	print(Clicker.Name.. " has recieved +5 health.")
	Clicker.Humanoid.Health = Clicker.Humanoid.Health + 5 
	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
	end
end)

1 comment

1

What's the point in using a for loop to go over one thing?

2 answers

✓ Accepted answer
script.Parent.ClickDetector.MouseClick:connect(function(Clicker)
    Clicker = Clicker.Character 
	if Clicker.Humanoid.Health < 100 then
    print(Clicker.Name.. " has recieved +5 health.")
    Clicker.Humanoid.Health = Clicker.Humanoid.Health + 5 
    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
    end
end
end)

Just add an if. If statements work like this if true then if it's false, it will go to else or elseif

if 2 == 1 then --false
	print"Are you sure?"
else print"Correctamundo!"
end

Elseif is like else and if combined(obviously).

if 2==1 then
	print"no"
elseif 2==3 then
	print"no"
elseif 2==2 then
	print"yes"
end

1 comment

0

Thanks, I tried this but I put the if statement somewhere's else.

below where clicker is defined put

if Clicker.Character.Humanoid.Health >= 100 then
--code
end

1 comment

0

I added this above the for i,v in pairs.

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