@Ovibion I think I fixed it, I tested it and it seemed to work properly. Let me know if anything is messed up. And you’re 100% right about me needing to make my code more organized, 9/10 times I have a bug and a simple change of code location in the script tends to fix it.
local Players = game:GetService("Players")
local LobbyTable = {}
local BattlegroundsTable = {}
local SwitchTablePart = game.Workspace["Switch To Battlegrounds Part"]
local Debounce = false
Players.PlayerAdded:Connect(function(player)
table.insert(LobbyTable, player)
print("Player added to the lobby table")
player.CharacterAdded:Connect(function(char)
if table.find(LobbyTable, player) then
print("Player located in lobby table")
local spawnFolder = game.Workspace:FindFirstChild("LobbySpawns")
local spawnLocations = spawnFolder:GetChildren()
local filteredLocations = {}
for i, location in ipairs(spawnLocations) do
if location.Name == "LobbySpawn" then
table.insert(filteredLocations, location)
end
end
local spawnLocation = filteredLocations[math.random(1,#filteredLocations)]
task.wait()
char:SetPrimaryPartCFrame(spawnLocation.CFrame)
elseif table.find(BattlegroundsTable, player) then
print("Player is located in the battlegrounds table spawn system")
local spawnFolder = game.Workspace:FindFirstChild("BattlegroundsSpawns")
local spawnLocations = spawnFolder:GetChildren()
local filteredLocations = {}
for i, location in ipairs(spawnLocations) do
if location.Name == "BattlegroundsSpawn" then
table.insert(filteredLocations, location)
end
end
local spawnLocation = filteredLocations[math.random(1,#filteredLocations)]
task.wait()
char:SetPrimaryPartCFrame(spawnLocation.CFrame)
end
end)
end)
SwitchTablePart.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Humanoid") then
if Debounce == false then
Debounce = true
table.insert(BattlegroundsTable, player)
print("Player successfully added to battlegrounds table")
table.remove(LobbyTable,table.find(LobbyTable,player))
print("Player successfully removed from lobby table")
wait(1)
Debounce = false
end
end
end)
Edit: nvm its still broken