I was trying to make it so everytime a player changes teams, they player gets a new model, but it wont work, No errors.
01 | local Player = game.Players.LocalPlayer |
02 | repeat wait() until Player.Character ~ = nil and Player.TeamColor ~ = BrickColor.new( "White" ) |
03 | local SquidModel = game.ReplicatedStorage.SharkModel |
04 | local DiverModel = game.ReplicatedStorage.DiverModel |
05 |
06 | function GiveParts(Model) |
07 | for _, Object in pairs (Model:GetChildren()) do |
08 | Object:Clone().Parent = Player.Character |
09 | end |
10 | end |
11 | function onChanged() |
12 | if Player.TeamColor = = BrickColor.new( "Crimson" ) then |
13 | GiveParts(SquidModel) |
14 | elseif Player.TeamColor = = BrickColor.new( "Medium blue" ) then |
15 | GiveParts(DiverModel) |
16 | elseif Player.TeamColor = = BrickColor.new( "Mid gray" ) then |
17 | GiveParts(DiverModel) |
18 | end |
19 | end |
20 | Player.Changed:connect(onChanged) |
THANKS
I believe that the Changed
event belongs to the Player instance, not the property, so you would change:
1 | Player.TeamColor.Changed:connect(onChanged) |
to:
1 | 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:
1 | function onChanged(property) |
There was also a check for this being equal to "TeamColor", like so:
01 | function onChanged(property) |
02 | if property = = "TeamColor" then |
03 | if Player.TeamColor = = BrickColor.new( "Crimson" ) then |
04 | GiveParts(SquidModel) |
05 | elseif Player.TeamColor = = BrickColor.new( "Medium blue" ) then |
06 | GiveParts(DiverModel) |
07 | elseif Player.TeamColor = = BrickColor.new( "Mid gray" ) then |
08 | GiveParts(DiverModel) |
09 | end |
10 | end |
11 | end |
This means your code will only run when the TeamColor property changes.