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)
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!