Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with changed event? [SOLVED][Edited]

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

1 comment

0

I've looked at everything and it dosen't look wrong, I dont see the error so i'll ask @BlueTaslem

1 answer

✓ Accepted answer

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.

7 comments

0

It only allows for change once, any ideas?

0

What do you mean by that? The question was a bit ambiguous.

0

Its no longer working

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.

0

? please explain more, with what you mean, and if you could, incorporate your answer into the code? im a bit confused

0

I just edited the original answer with a bit of a better explanation.

0

Awesome thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.