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