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

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

Asked by 3 years ago

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

0
remove the other greater than operator (>) in 2 and 40 it should be if humanoid.Helth < 60 and 50 then JesseSong 3916 — 3y
0
also, elseif humanoid.health <50 and 40 then JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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


0
Thank you for the help! Zeta_Dev 34 — 3y
Ad

Answer this question