I made a switching teams script, and I tried it, but it didn't work. There was NO error output, but there was a bug as there was the not changing teams. Whenever I called the script to do something, it stay the same on the Player.TeamColor value and the leaderstats. Any solutions?
Faulty code 1:
local replicated = game:GetService("ReplicatedStorage")
--ERROR
replicated.ChangeTeam.OnClientEvent:connect(function(...)
local tuple = {...}
if tuple[1] == "Orange Team" then
if tuple[2] then
local name = tuple[2]
game.Players[name].TeamColor = BrickColor.new(1005)
end
elseif tuple[1] == "Green Team" then
if tuple[2] then
local name = tuple[2]
game.Players[name].TeamColor = BrickColor.new(313)
end
elseif tuple[1] == "Yellow Team" then
if tuple[2] then
local name = tuple[2]
game.Players[name].TeamColor = BrickColor.new(1009)
end
end
end)
Faulty code 2:
local replicated = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local Name = player.Name
local team = game:WaitForChild("Teams")
--ERROR
while true do
if replicated.Race.Value == false then
if game.Players.NumPlayers <= 3 then
while true do
if game.Players.NumPlayers >= 3 then
break
else
wait (2)
end
end
end
background.Visible = false
local newteam = math.random(#team, 1)
replicated.ChangeTeam.FireAllClients(newteam, player.Name)
elseif replicated.Race.Value == true then
background.Visible = true
end
wait(2)
end

1 comment
Your script does not explain or narrow down the problem to a few lines of code. Please include information such as, errors, what line does the script stop on, what do you believe the problem may be, etc. We can not go based off just reading code as all games, and all scripts are different. Thank you.