✓ Accepted answer
What you have set up right now inserts a new clone of AgentLeftArm in Workspace every time ANY property of the Player is changed. You are looking to see if a specific property [TeamColor] is changed to a specific value [BrickColor.new("Bright blue")].
local player = game.Players.LocalPlayer
local teamColor = BrickColor.new("Bright blue")
player.Changed:connect(function(property)
if property == "TeamColor" then
if player.TeamColor == teamColor then
local mesh = game.Workspace.AgentLeftArm:Clone()
mesh.Parent = player.Character
end
end
end)
But if I character respawns, the TeamColor property doesn't change. If you want to insert it into the character if it spawns in on the Bright blue Team then you'll need to have a CharacterAdded function as well.
local player = game.Players.LocalPlayer
local teamColor = BrickColor.new("Bright blue")
player.CharacterAdded:connect(function()
if player.TeamColor == teamColor then
repeat wait() until character:FindFirstChild("Humanoid")
local mesh = game.Workspace.AgentLeftArm:Clone()
mesh.Parent = player.Character
end
end)
player.Changed:connect(function(property)
if property == "TeamColor" then
if player.TeamColor == teamColor then
local mesh = game.Workspace.AgentLeftArm:Clone()
mesh.Parent = player.Character
end
end
end)
EDIT FIXED
local teamColor = BrickColor.new("Bright blue")
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
if player.TeamColor == teamColor then
repeat wait() until character:FindFirstChild("Humanoid")
local mesh = game.Workspace.AgentLeftArm:Clone()
mesh.Parent = character
end
end)
player.Changed:connect(function(property)
if property == "TeamColor" then
if player.TeamColor == teamColor then
local mesh = game.Workspace.AgentLeftArm:Clone()
mesh.Parent = player.Character
end
end
end)
end)
2 comments
If you provide the output, if any, that could really help us help you! Also, is this a local script?
Yes, this is a localscript - and I don't seem to be getting any output :(