My script is not changing the colour of the player when it dies

bodyColors = {'HeadColor', 'LeftArmColor', 'LeftLegColor', 'RightArmColor', 'RightLegColor', 'TorsoColor'}

local dead = false
for i, v in pairs(game.Players:GetPlayers()) do
	if v.health == 0 then
		local dead = true
		if dead == true then	
	for _,color in pairs(bodyColors) do
    v["Body Colors"][color] = BrickColor.new("Institutional white")

	end
	end
end
end

Try printing v[‘Body Colors’]

Are you sure that is the right place?

Also, the died bool is completely pointless.

After further inspection, you are indexing players instead of characters. Try this:

bodyColors = {'HeadColor', 'LeftArmColor', 'LeftLegColor', 'RightArmColor', 'RightLegColor', 'TorsoColor'}

game.Players.PlayerAdded:Connect(function(p)
   p.CharacterAdded:Connect(function(c)
       c:WaitForChild("Humanoid").Died:Connect(function()
         for _,color in pairs(bodyColors) do
            c["Body Colors"][color] = BrickColor.new("Institutional white")
         end
      end)
   end)
end)

Oh thanks it works, however how can i make it so it keeps the colour instead of resetting once i die?

So

  • Player dies
  • Player respawns white?

Try this

bodyColors = {'HeadColor', 'LeftArmColor', 'LeftLegColor', 'RightArmColor', 'RightLegColor', 'TorsoColor'}

local function colorChar(c)
    for _,color in pairs(bodyColors) do
            c["Body Colors"][color] = BrickColor.new("Institutional white")
     end
end

game.Players.PlayerAdded:Connect(function(p)
local hasDied = false
   p.CharacterAdded:Connect(function(c)
       if hasDied then
          colorChar(c)
       end 
       c:WaitForChild("Humanoid").Died:Connect(function()
         hasDied = true
         colorChar()
      end)
   end)
end)

oh yea thats what i was tryingto do thank you so much

Remember to mark the solution through the checkbox icon you find under the post that solves your problem. This will aid the community’s time of finding the solution faster by searching, if they had a similar problem.

:dark_sunglasses: