Question

    for index, each in pairs (game.Players:GetPlayers()) do
    if each.TeamColor == BrickColor.new("White") then

    each.TeamColor = BrickColor.new("Bright red")
        each.Character:BreakJoints()
        redCount = redCount + 1
        -- Wont load character appearance when they start the game
        each.CanLoadCharacterAppearance = false
        each.Character.Torso.BrickColor = BrickColor.new("Bright red")
        each.Character["Right Arm"].BrickColor = BrickColor.new("Bright red")
        each.Character["Left Arm"].BrickColor = BrickColor.new("Bright red")

The problem is where I need to change what the user looks like but when I try it the character doesn't change to the new colour. The character appearances doesn't load but it doesn't change their color. This is laser tag game, so this is at the beginning of the game when its chooses teams and gives them color. I was wondering if someone could explain it to me.

Also when I say

each.CanLoadCharacterAppearance = false
each.Character.Torso.BrickColor = BrickColor.new("Bright red")
each.Character["Right Arm"].BrickColor = BrickColor.new("Bright red")

will I have to say that every time they respawn or will they have the same colour after they die.

Was it helpful?

Solution

The Character property of the Player class is not an Object in itself. But it is a pointer to the character model that usually resides in the Workspace (the name of the model is the same as the playername).

Thus every change to Player.Character will reset when the player's character respawn.

In your case you first kill the character

each.Character:BreakJoints()

And then change the color of the character's torso

each.Character.Torso.BrickColor = BrickColor.new("Bright red")

To be noted here is that the character do NOT respawn immediately when it dies, thus your changes to the color is made on the remains of the character (the ones that gets removed after a respawn) and not the new one.


A good way to fix this would be to use:

Game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        Character.Torso.BrickColor = Player.TeamColor
    end)
end)

The event Player.CharacterAdded is fired every time the Player's character are respawned, thus this code makes sure that the player's character's torso always is the same color as the player's team.

When you then want to respawn the players just do:

for i,Player in ipairs(Game.Players:GetPlayers()) do
    Player:LoadCharacter()
end

Note that Player:LoadCharacter() respawn the characters immediately (you can use Character:BreakJoints() instead, but Player:LoadCharacter() is neater).

Also remember that you still need to change the Player.TeamColor before you respawn the character.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top