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

Humanoid:GetPropertyChangedSignal(“Health”):Connect(function()
if Humanoid.Health <= 20 and Player.Team == game.Teams.Players and not Humanoid.Health == 0 then
Player.TeamColor = BrickColor.new(“Really red”)
end
end)

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

Humanoid.HealthChanged:Connect(function(Health)
	if Health <= 20 and Health > 0 and Player.Team == game.Teams.Players then
		Player.TeamColor = BrickColor.new("Really red")
	end
end)

https://developer.roblox.com/en-us/api-reference/event/Humanoid/HealthChanged

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.

https://developer.roblox.com/en-us/api-reference/property/Player/TeamColor

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 = Instance.new(“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”
script.Parent.Animate.run.RunAnim.AnimationId = “rbxassetid://8177414818”
script.Parent.Animate.walk.WalkAnim.AnimationId = “rbxassetid://8177414818”
Character.InfectedHumanoid.Animator:LoadAnimation(newAnim):Play()
wait(8)
Character.InfectedHumanoid.WalkSpeed = 10
Character.InfectedHumanoid.JumpPower = 20
Team_Player = false
script.Parent.InfectHitScript.Disabled = false
Player.PlayerGui.InfectedPunchGui.Enabled = true
Player.Backpack:ClearAllChildren()
if Character:FindFirstChild(“Club”) then
Character.Club:Destroy()
end
end

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

nvm ill make a new forum i guess