Script doesnt change player health when on certain team

local player = game.Players.LocalPlayer

while true do

if player and player.TeamColor == BrickColor.new(“Mint”) then

workspace[player.Name]:FindFirstChild(“Humanoid”).Health = 250

end

wait(0.1)

end
This script doesnt change the health of the player when they are on the team with the brick color “mint”. Can somebody help me please?

W h a t

You’re trying to get the Player’s name in the workspace? I think it’s a simple fix just by doing:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

if Player and Player.TeamColor == BrickColor.new("Mint") then
    Character.Humanoid.MaxHealth = 250
    Character.Humanoid.Health = 250
    wait(.1)
end

Another thing to note is that just changing the Health alone won’t work, so you need to change the MaxHealth first then Health next

Using a loop could cause lag, so it’s probably better to check when the TeamColor property is changed:

Player:GetPropertyChangedSignal("TeamColor"):Connect(function()
-- code
end)
1 Like

I didn’t even include a loop in my code but ok that works too

I don’t think it’ll exactly work client sided so you may need to do it on the server instead?

Doesn’t work still. I still have 100 health.

Are you getting any errors from the scirpt?

No, I havep ut the script i nworkspace.

I’d try this:

  • Put a script in ServerScriptService
  • Put this code inside:
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player) -- This function is called everytime a player joins the game
	player:GetPropertyChangedSignal("TeamColor"):Connect(function()
		-- This function is called everytime the "TeamColor" property of the player is changed
		if player.TeamColor == BrickColor.new("Mint") then
			local character = player.Character or player.CharacterAdded:Wait()
			character.Humanoid.MaxHealth = 250
			character.Humanoid.Health = 250
		end
	end)
end)
1 Like

Still doesnt work. Tried it and doesnt work.

Try this?

--ServerScriptService (It needs to be a regular script, not a Local)

game.Players.PlayerAdded:Connect(function(Player)  
    Player.CharacterAdded:Connect(function(Character)
        print(Player.TeamColor)
        if Player.TeamColor == BrickColor.new("Mint") then
            Character.Humanoid.MaxHealth = 250
            Character.Humanoid.Health = 250
        end
    end)
end)

I’m on mobile send help

1 Like