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 8 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.

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

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

1 answer

Log in to vote
1
Answered by 8 years ago

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.

0
It only allows for change once, any ideas? pluginfactory 463 — 8y
0
What do you mean by that? The question was a bit ambiguous. IDidMakeThat 1135 — 8y
0
Its no longer working pluginfactory 463 — 8y
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 — 8y
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 — 8y
0
I just edited the original answer with a bit of a better explanation. IDidMakeThat 1135 — 8y
0
Awesome thanks pluginfactory 463 — 8y
Ad

Answer this question