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

How do i check the localplayer's humanoid health between a certain point?

So I'm trying to make a local script that checks the player's health in between a point. For ex:

local humanoid = game:GetService("Players").LocalPlayer.Character.Humanoid
if humanoid.Health < 60 and > 50 then
	script.Parent.ImageLabel.ImageTransparency = 0.8
elseif humanoid.Health < 50 and > 40 then
	script.Parent.ImageLabel.ImageTransparency = 0.8
end

This is the script I wrote and it doesn't work. I don't know how to check what health the player has in between those numbers without it erroring. Thank you for your time. - Zeta

2 comments

0

remove the other greater than operator (>) in 2 and 40 it should be if humanoid.Helth < 60 and 50 then

0

also, elseif humanoid.health <50 and 40 then

1 answer

✓ Accepted answer

##Problem:

You're using 2 operators in the same line, which cannot work

EX:

if humanoid.Health <60 and > 50 then

The above code will not work because you've already inputted an operator

##Simple Fix:

Just remove one of the operators and that will fix your issue.

NOTE:

It's also good to constantly check for the player's health by either using a loop or .HealthChanged or the code will only check once.

Fixed Code:

local humanoid = game:GetService("Players").LocalPlayer.Character.Humanoid
humanoid.HealthChanged:Connect(function(health) 
	
if humanoid.Health < 60 and  50 then
	print ("yes") -- it's there just for debugging purposes
elseif humanoid.Health < 50 and 40 then
	script.Parent.ImageLabel.ImageTransparency = 0.8
end
	
end)

Or if you wanted it to do it only once just remove the connect function:

local humanoid = game:GetService("Players").LocalPlayer.Character.Humanoid
	
if humanoid.Health < 60 and  50 then
	print ("yes")
elseif humanoid.Health < 50 and 40 then
	script.Parent.ImageLabel.ImageTransparency = 0.8
end
	

1 comment

0

Thank you for the help!

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