When a player presses a “Team Change” button, they are getting teamed in one of 2 teams
when the player joins, he is in the “Spectator” team, they can only join a battle when they changed their team.
My problem:
I have to reset my character after I change my team from spectator to be able to play.
I think this is because the script isn’t detecting any team change even if the team for the player is changed
The script that causes the problem:
local function Play()
if playerteam == Spectators then
PlayButton.Text ="Please Change Your Team"
ErrorSound:Play()
wait(3)
PlayButton.Text ="Play"
else
SpawnWeaponRE:FireServer(player)
MainMenu:Destroy()
LobbyMusic.Volume = 0
ClickSound:Play()
end
end
PlayButton.MouseButton1Down:Connect(function()
Play()
end)
Also, here is the Serverscript if it might help with my problem:
ChangeTeam.OnServerEvent:Connect(function(Player)
local TeamName = Player.Team.Name
if Player.TeamColor == Catunion and DogTeamCount<=CatTeamCount then -- DOGUNION
Player.TeamColor = Dogunion
CatTeamCount = CatTeamCount-1
DogTeamCount = DogTeamCount+1
CatTeamCLS = CatTeamCount
DogTeamCLS = DogTeamCount
elseif Player.TeamColor == Dogunion and CatTeamCount<=DogTeamCount then -- CATUNION
Player.TeamColor = Catunion
CatTeamCount = CatTeamCount+1
DogTeamCount = DogTeamCount-1
CatTeamCLS = CatTeamCount
DogTeamCLS = DogTeamCount
elseif Player.TeamColor == Spectator then -- IF SPECTATOR ChangeTeam
if CatTeamCount<=DogTeamCount then -- CATUNION
Player.TeamColor = Catunion
CatTeamCount = CatTeamCount+1
DogTeamCount = DogTeamCount-1
CatTeamCLS = CatTeamCount
DogTeamCLS = DogTeamCount
elseif DogTeamCount<=CatTeamCount then -- DOGUNION
Player.TeamColor = Dogunion
CatTeamCount = CatTeamCount-1
DogTeamCount = DogTeamCount+1
CatTeamCLS = CatTeamCount
DogTeamCLS = DogTeamCount
else -- ELSE DOGUNION
Player.TeamColor = Dogunion
DogTeamCount = DogTeamCount+1
DogTeamCLS = DogTeamCount
end
end
if Player.TeamColor == Dogunion then
for _, Accs in pairs(DUAccs:GetChildren()) do
local clone = Accs:Clone()
clone.Parent = Player.Character
end
elseif Player.TeamColor == Catunion then
for _, Accs in pairs(CUAccs:GetChildren()) do
local clone = Accs:Clone()
clone.Parent = Player.Character
end
end
end)```