Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago

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)

0
Is that a local script or a server script? Happy_Liam 64 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

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. AnonymationBeatMusic 7 — 4y
Ad

Answer this question