Need help with roblox teams

Hey so I’m making a roblox game I have a bug. I have it so when you spawn in your team is automatically switched based on a group rank. I have this script that gives you a starter weapon when you spawn in depending on the team you are on. Since it takes a delay to switch teams It does not actually give you the team weapon unless you reset. Does anyone know how to fix this or have like a script that detects when you switch teams and resets you. Please help!

Can you add the script please?

can you post the script so we can see it? please

game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(9716157) == 1 then
plr.TeamColor = BrickColor.new(“Sea green”)
end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 2 then
		plr.TeamColor = BrickColor.new("Bright orange")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 3 then
		plr.TeamColor = BrickColor.new("New Yeller")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 4 then
		plr.TeamColor = BrickColor.new("Persimmon")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 254 then
		plr.TeamColor = BrickColor.new("Electric blue")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 255 then
		plr.TeamColor = BrickColor.new("Lime green")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(9716157) == 1 then
plr.TeamColor = BrickColor.new(“Sea green”)
end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 2 then
		plr.TeamColor = BrickColor.new("Bright orange")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 3 then
		plr.TeamColor = BrickColor.new("New Yeller")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 4 then
		plr.TeamColor = BrickColor.new("Persimmon")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 254 then
		plr.TeamColor = BrickColor.new("Electric blue")
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup(9716157) == 255 then
		plr.TeamColor = BrickColor.new("Lime green")
	end
end)

function teamFromColor(color)
for _,t in pairs(game:GetService(“Teams”):GetChildren()) do
if t.TeamColor==color then return t end
end
return nil
end

function onSpawned(plr)
local tools = teamFromColor(plr.TeamColor):GetChildren()
for _,c in pairs(tools) do
c:Clone().Parent = plr.Backpack
end
end

function onChanged(prop,plr)
if prop==“Character” then
onSpawned(plr)
end
end

function onAdded(plr)
plr.Changed:connect(function(prop)
onChanged(prop,plr)
end)
end

game.Players.PlayerAdded:connect(onAdded)

I’m so stupid I just added a wait and now it works :expressionless:

1 Like