This script is supposed to create a selection box, and place it in the user's Left Arm. The script is supposed to make the SelectionBox "Cyan" by default, but if the players teamcolor is "Bright red" then make the selection box color "Bright red". The problem is that the SelectionBox is always red for all the characters, even if they aren't on the red team.
game.Workspace.ChildAdded:connect(function(Character) wait() repeat wait() until game.Players.LocalPlayer local p = game.Players.LocalPlayer local box = Instance.new("SelectionBox") box.Parent = Character["Right Arm"] box.Adornee = Character["Right Arm"] box.Color = BrickColor.new("Cyan") wait() if p.TeamColor == BrickColor.new("Bright red") then wait(.5) box.Color = BrickColor.new("Bright red") end end)
I don't know why the if statement would return true, but your script is very error friendly. You should use the PlayerAdded
and CharacterAdded
events from a server script in workspace, instead of ChildAdded
from a local script. Also, since the ChildAdded
event fires every time a new child enters workspace, on the case that it's not a character, line 06 and 07 will break.
game.Players.PlayerAdded:connect(function(plr) --When a player joins plr.CharacterAdded:connect(function(chr) --When a chr is added to the plr wait(0.1) --Helps prevent errors. local box = Instance.new("SelectionBox", chr["Right Arm"]) --Create the SB in your right arm box.Adornee = chr["Right Arm"] --Make it show up on the right arm if plr.TeamColor == BrickColor.new("Bright red") then --If the teamcolor's red box.Color = BrickColor.new("Bright red") --Make the box red else --otherwise, box.Color = BrickColor.new("Cyan") --Make it cyan end end) end)