I was trying to make it so everytime a player changes teams, they player gets a new model, but it wont work, No errors.
local Player = game.Players.LocalPlayer repeat wait() until Player.Character ~= nil and Player.TeamColor ~= BrickColor.new("White") local SquidModel = game.ReplicatedStorage.SharkModel local DiverModel = game.ReplicatedStorage.DiverModel function GiveParts(Model) for _, Object in pairs(Model:GetChildren()) do Object:Clone().Parent = Player.Character end end function onChanged() if Player.TeamColor == BrickColor.new("Crimson") then GiveParts(SquidModel) elseif Player.TeamColor == BrickColor.new("Medium blue") then GiveParts(DiverModel) elseif Player.TeamColor == BrickColor.new("Mid gray") then GiveParts(DiverModel) end end Player.Changed:connect(onChanged)
THANKS
I believe that the Changed
event belongs to the Player instance, not the property, so you would change:
Player.TeamColor.Changed:connect(onChanged)
to:
Player.Changed:connect(onChanged)
I hope this helps.
EDIT: I noticed that previously, you had an argument to onChanged
. I can't remember its name, but it looked a bit like this:
function onChanged(property)
There was also a check for this being equal to "TeamColor", like so:
function onChanged(property) if property == "TeamColor" then if Player.TeamColor == BrickColor.new("Crimson") then GiveParts(SquidModel) elseif Player.TeamColor == BrickColor.new("Medium blue") then GiveParts(DiverModel) elseif Player.TeamColor == BrickColor.new("Mid gray") then GiveParts(DiverModel) end end end
This means your code will only run when the TeamColor property changes.