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

how do i change a StarterCharacter's block colors for teams?

I'm trying to change a characters head color by teams and the script i am making

local player = game.Players.LocalPlayer

while true do
	
if player.Team == game:GetService("Teams").Blue then

Starter.Head.BrickColor = BrickColor.new("Really blue") else

if player.Team == game:GetService("Teams").Red then
	
Starter.Head.BrickColor = BrickColor.new("Really red") else

if player.Team == game:GetService("Teams").Green then
	
Starter.Head.BrickColor = BrickColor.new("Lime green") else
	
if player.Team == game:GetService("Teams").Lobby then
	
Starter.Head.BrickColor = BrickColor.new("Medium stone grey")
	
	
	    end
         end
      end
   end
end


this is a local script because i am trying to target the player on teams so when on a team your character changes its look, in the developer console it says line 5: Attempt to index local 'player' (a nil value)

1 comment

0

Is that a local script or a server script?

1 answer

✓ Accepted answer

Alright, so what we wanna do is we wanna make an event that listens for a change in the player's team color, and we do this by using the :GetPropertyChangedSignal() event. So every time the team color changes, the player head color changes. Don't forget to set the player's head color after or before the event because the event will not detect a team color change when the game starts due to the fact the player loads before the character.

-- SCRIPT IN STARTERCHARACTERSCRIPTS!!!
local Players = game:GetService("Players")

local character = script.Parent
local head = character:WaitForChild("Head")
local player = Players:GetPlayerFromCharacter(character)

player:GetPropertyChangedSignal("TeamColor"):Connect(function() 
	head.BrickColor = player.TeamColor
end)

wait(1)
head.BrickColor = player.TeamColor

Hope I could help you!

1 comment

0

this helped accomplish making the head turn the team color but how would i go about doing all the parts of a player, do i simply copy line 5, 9, and 13 then rename head to the part.

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