Health script not working

This line of code isn’t working and if the player dies it somehow survives it when it was even intentional. I’m trying to track if the players health is lower than 20 but not 0 and everytime I do it doesn’t work and it just does nothing. No errors though which was odd. My question is how do I check if the players health is lower than 20 and not dead?

Would you be able to provide the code you need help with?

yeah sure

if Humanoid.Health <= 20 and Player.Team == game.Teams.Players and not Humanoid.Health == 0 then
Player.TeamColor =“Really red”)

if you want a video of what happens I can record it

	if Health <= 20 and Health > 0 and Player.Team == game.Teams.Players then
		Player.TeamColor ="Really red")

I also changed how checking if the health is above 0 is performed.

1 Like

thank you! Let me test it out.

not Humanoid.Health == 0 translates in a weird way that’s why we instead use ~= to say “no equal”.

I have forgotten about that but thank you!

1 Like
Player.Team = game.Teams.Red

I would also assign the Team property of the player as opposed to the TeamColor property.

It’s often a better idea to set Player.Team to the respective Team instead of using this property. Setting this property often leads to repetition of the same BrickColor value for a certain teams across many scripts; this is something you want to avoid when adhering to the don’t-repeat-yourself principle.

the solution worked but now my other script is functioning weird.

try adding Humanoid.Health ~= 0.

1 Like

now i have another error which is the protection barrier that kills people that are in the team infected.

it doesn’t kill them as it should

I think this is the line of code thats breaking

if Player.Team == game.Teams.Infected then
if Team_Player == true then
Character.Humanoid.Name = “InfectedHumanoid”
local newAnim =“Animation”)
newAnim.AnimationId = InfectAnim
Character.InfectedHumanoid.WalkSpeed = 0
Character.InfectedHumanoid.JumpPower = 0
Character.InfectedHumanoid.MaxHealth = 55
Character.InfectedHumanoid.Health = Character.InfectedHumanoid.MaxHealth
script.Parent.Animate.idle.Animation1.AnimationId = “rbxassetid://8177163203”
script.Parent.Animate.idle.Animation2.AnimationId = “rbxassetid://8177163203” = “rbxassetid://8177414818”
script.Parent.Animate.walk.WalkAnim.AnimationId = “rbxassetid://8177414818”
Character.InfectedHumanoid.WalkSpeed = 10
Character.InfectedHumanoid.JumpPower = 20
Team_Player = false
script.Parent.InfectHitScript.Disabled = false
Player.PlayerGui.InfectedPunchGui.Enabled = true
if Character:FindFirstChild(“Club”) then

im pretty sure its due to the character.infectedhumanoid.maxhealth = 55

nvm ill make a new forum i guess