Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Help with changed event? [SOLVED][Edited]

Asked by 9 years ago

I was trying to make it so everytime a player changes teams, they player gets a new model, but it wont work, No errors.

01local Player = game.Players.LocalPlayer
02repeat wait() until Player.Character ~= nil and Player.TeamColor ~= BrickColor.new("White")
03local SquidModel = game.ReplicatedStorage.SharkModel
04local DiverModel = game.ReplicatedStorage.DiverModel
05 
06function GiveParts(Model)
07    for _, Object in pairs(Model:GetChildren()) do
08        Object:Clone().Parent = Player.Character
09    end
10end
11function onChanged()
12if Player.TeamColor == BrickColor.new("Crimson") then
13    GiveParts(SquidModel)
14elseif Player.TeamColor == BrickColor.new("Medium blue") then
15    GiveParts(DiverModel)
16elseif Player.TeamColor == BrickColor.new("Mid gray") then
17    GiveParts(DiverModel)
18end
19end
20Player.Changed:connect(onChanged)

THANKS

0
I've looked at everything and it dosen't look wrong, I dont see the error so i'll ask @BlueTaslem funzrey 58 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

I believe that the Changed event belongs to the Player instance, not the property, so you would change:

1Player.TeamColor.Changed:connect(onChanged)

to:

1Player.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:

1function onChanged(property)

There was also a check for this being equal to "TeamColor", like so:

01function 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
11end

This means your code will only run when the TeamColor property changes.

0
It only allows for change once, any ideas? pluginfactory 463 — 9y
0
What do you mean by that? The question was a bit ambiguous. IDidMakeThat 1135 — 9y
0
Its no longer working pluginfactory 463 — 9y
0
I just noticed you seem to have got rid of the argument for onChanged, as well as the check for it being equal to "TeamColor". That could be the problem. IDidMakeThat 1135 — 9y
View all comments (3 more)
0
? please explain more, with what you mean, and if you could, incorporate your answer into the code? im a bit confused pluginfactory 463 — 9y
0
I just edited the original answer with a bit of a better explanation. IDidMakeThat 1135 — 9y
0
Awesome thanks pluginfactory 463 — 9y
Ad

Answer this question