Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change color of a custom character on a respawn?

as always, the question sounds confusing but what i'm saying is that, how do I change the color of the part in the custom character (lets say like Torso for example when ever a player respawns it changes color). I'm trying to change up the hat color I've added on my custom character for player to play as. Each time they respawn, the hat changes colors but my scripting seems a bit off, and it's not working.

local Players = game:GetService("Players")

  

local function onCharacterAdded(character)

character.ShadowMaskGiver.Color.BrickColor.BrickColor = BrickColor.Random()

end```

3 comments

0

ignore the "```" part at the end, that isn't part of the script.

0

I found that adding wait(1) does the trick

0

that doesn't seem to work, What really bothers me is that nothing is showing in the output.

1 answer

✓ Accepted answer

It seems like you are not firing the function, instead try this:

local plr = game:GetService("Players")
plr.PlayerAdded:wait() --- i think this line is not needed but just in case
plr.LocalPlayer.CharacterAdded:Connect(function(char)
    character.ShadowMaskGiver.Color.BrickColor.BrickColor = BrickColor.Random()
end)

or if you want something longer you can try:

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		character.ShadowMaskGiver.Color.BrickColor.BrickColor = BrickColor.Random()
	end)
end)	       

either that or you can simply add this line at the bottom of your script, this line fires your function:

Players.LocalPlayer.CharacterAdded:Connect(OnCharacterAdded)

1 comment

0

The 'char' is supposed to be 'character' but i forgot to change it also it won't let me edit it properly

This discussion is preserved as it was. New answers, comments, and votes are closed.