Ello Everyone! So my friend and co-developer added this script for team balancing (FPS game).
For some reason, its a 50/50 that you get on the correct team.
The code is here, I have tried to debug this wayy to many times.
local function onPlayerAdded(player)
print("Player added "..player.Name)
local PlayerJustJoined=true
--player:LoadCharacter()
local function onCharacterAdded(character)
print(character.Name .. " has spawned")
if PlayerJustJoined==true then
PlayerJustJoined=false
if GameHasStarted.Value==true then
local SelectedMap=game.ServerStorage.GameData.ServerData.MapData.SelectedMap
print("SelectedMap.Value= "..SelectedMap.Value)
local Map_Clone=workspace:FindFirstChild(SelectedMap.Value)
print("Map_Clone Name.."..Map_Clone.Name)
local MapSpawns=Map_Clone.Spawns
BlueSpawns=MapSpawns.Blue:GetChildren()
RedSpawns=MapSpawns.Red:GetChildren()
--for i,v in pairs(PlayerTeams:GetChildren()) do
-- local TablePlayer=v[1]
-- local TableTeam=v[2]
-- if TableTeam==BlueTeam then
-- BlueTeamSize_FromTable=BlueTeamSize_FromTable+1
-- elseif TableTeam==RedTeam then
-- RedTeamSize_FromTable=RedTeamSize_FromTable+1
-- end
--end
--print("BlueTeamSize "..BlueTeamSize)
--print("RedTeamSize "..RedTeamSize)
print("BlueTeamSize_FromTable "..BlueTeamSize_FromTable)
print("RedTeamSize_FromTable "..RedTeamSize_FromTable )
if BlueTeamSize_FromTable==RedTeamSize_FromTable then
local TeamPickedRandomSeed=math.random(1,100)
if TeamPickedRandomSeed<=50 then
--BlueTeamSize=BlueTeamSize+1
player.Team=BlueTeam
--table.insert(PlayerTeams,{player.Name,BlueTeam})
SpawnPlayer(player,BlueSpawns)
else
--RedTeamSize=RedTeamSize+1
player.Team=RedTeam
--table.insert(PlayerTeams,{player.Name,RedTeam})
SpawnPlayer(player,RedSpawns)
end
elseif BlueTeamSize_FromTable<RedTeamSize_FromTable then--if BlueTeamSize<RedTeamSize then
print("Was less Blue team")
--BlueTeamSize=BlueTeamSize+1
BlueTeamSize_FromTable=BlueTeamSize_FromTable+1
player.Team=BlueTeam
SpawnPlayer(player,BlueSpawns)
--table.insert(PlayerTeams,{player.Name,BlueTeam})
elseif RedTeamSize_FromTable<BlueTeamSize_FromTable then --elseif RedTeamSize<BlueTeamSize then
print("Was less Red team")
--RedTeamSize=RedTeamSize+1
RedTeamSize_FromTable=RedTeamSize_FromTable+1
player.Team=RedTeam
--table.insert(PlayerTeams,{player.Name,RedTeam})
SpawnPlayer(player,RedSpawns)
end
insertTeamMarker(player)
Events.HideGui:FireAllClients(player)
--Players.PlayerRemoving:Connect(function(LeavingPlayer)
-- print(LeavingPlayer.Name + " left the game!")
-- if LeavingPlayer==player then
-- end
--end)
DocumentTeamMember(player)
end
elseif GameHasStarted.Value==true then
--local PlayerGui=player.PlayerGui
--local RespawningGui=script.RespawningGui:Clone()
--local RespawningEvent=game.ReplicatedStorage.Events.Status.Respawning
--delay(1,function()
-- RespawningEvent:FireClient(player)
--end)
--local RespawningGui=game.ServerStorage.RespawningGui:Clone()
--print(RespawningGui.Name)
--RespawningGui.Parent=player.PlayerGui
--print(RespawningGui.Parent)
----RespawningGui.Status.RespawnGuiTimer.Disabled=false
--print("Added respawning GUI")
--print(player.Name)
local SelectedMap=game.ServerStorage.GameData.ServerData.MapData.SelectedMap
print("SelectedMap.Value= "..SelectedMap.Value)
--local Map_Clone=workspace:WaitForChild(SelectedMap.Value,5)
local Map_Clone=workspace:FindFirstChild(SelectedMap.Value)
--:FindFirstChild(SelectedMap.Value)
if Map_Clone and GameHasStarted.Value==true then
print("Map_Clone Name.."..Map_Clone.Name)
local MapSpawns=Map_Clone.Spawns
BlueSpawns=MapSpawns.Blue:GetChildren()
RedSpawns=MapSpawns.Red:GetChildren()
delay(2,function()
if GameHasStarted.Value==true then
if player.Team==BlueTeam then
SpawnPlayer(player,BlueSpawns)
elseif player.Team==RedTeam then
SpawnPlayer(player,RedSpawns)
end
end
end)
end
end
--local PlayerGui=player.PlayerGui
--local RespawningGui=script.RespawningGui:Clone()
--RespawningGui.Parent=PlayerGui
--print("Player RespawnIn Map01")
--if player.Team==BlueTeam then
-- SpawnPlayer(player,BlueSpawns)
--elseif player.Team==RedTeam then
-- SpawnPlayer(player,RedSpawns)
--end
--delay(2,function()
-- print("Player RespawnIn Map02")
-- if player.Team==BlueTeam then
-- SpawnPlayer(player,BlueSpawns)
-- elseif player.Team==RedTeam then
-- SpawnPlayer(player,RedSpawns)
-- end
--end)
--character.Humanoid.Died:Connect(function()
-- character:Destroy()
-- player:LoadCharacter()
--end)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)
We are aiming at a release tomorrow, so any help would be nice (Yes his code is spaghetti code, he just doesn’t have posting access to get help)