Team Change Problem

Hello.
I’m working on a Jersey changer/giver system. I’ve ran into a problem were once you change the team from “Media” to “Home” the transfer is fine. But when changing from “Home” to “Media” the transfer only transfers the uniform folder but not the accessories back to the character. Why is this happening?

Code:

local function TeamCheck(Team)
if Team == 'Fans' or Team == 'Media' or Team == 'Officials' then
		for _,V in pairs(Character:GetChildren()) do
			if V.ClassName == 'Accessory' or V.ClassName == 'Pants' or V.ClassName == 'Shirt' or V.ClassName == 'ShirtGraphic' then
				V.Parent = Character
			end
			if V.Name == 'Uniform' then
				V.Parent = Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId)
			end
		end
	else
		for _,V in pairs(Character:GetChildren()) do
			if V.ClassName == 'Accessory' or V.ClassName == 'Pants' or V.ClassName == 'Shirt' or V.ClassName == 'ShirtGraphic' then
				V.Parent = Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId)
			end
			if Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId):FindFirstChild('Uniform') then
				Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId):FindFirstChild('Uniform').Parent = Character
			end
		end
	end
end
--```

Have you tried making points in your script where it will print a Error if a certain Part does not succeed? That way we can know where the script stopped and which line confused the script and messed it up.

1 Like

I’ve tried everything. Looking for where the script bugs out, Rescripting it everything. I don’t know what’s happening.

  1. You should use the IsA() to check/compare classes.
  2. Where are you calling that function? Could you show more of the code?
local function TeamCheck(Team)
	if Team == 'Fans' or Team == 'Media' or Team == 'Officials' then
		for _,V in pairs(Character:GetChildren()) do
			if V.ClassName == 'Accessory' or V.ClassName == 'Pants' or V.ClassName == 'Shirt' or V.ClassName == 'ShirtGraphic' then
				if V.Parent ~= Character then
					Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId):FindFirstChild(V).Parent = Character
				end
			end
			if V.Name == 'Uniform' then
				V.Parent = Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId)
			end
		end
	else
		for _,V in pairs(Character:GetChildren()) do
			if V.ClassName == 'Accessory' or V.ClassName == 'Pants' or V.ClassName == 'Shirt' or V.ClassName == 'ShirtGraphic' then
				V.Parent = Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId)
			end
			if Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId):FindFirstChild('Uniform') then
				Replicated:FindFirstChild('DataHolder'):FindFirstChild(Player.UserId):FindFirstChild('Uniform').Parent = Character
			end
		end
	end
end


LoadTeam(Player.Team.Name)
TeamCheck(Player.Team.Name)
--
Player.Changed:Connect(function()
	LoadTeam(Player.Team.Name)
	TeamCheck(Player.Team.Name)
end)