Both scripts are ServerScripts inside the ServerScriptService
Alright, so I designed two scripts, one that distributes rooms into the workspace, and the other placing the users within a room which is not occupied by another player. However my issue is the room assigning script placing the players within a unoccupied room. The script below. . .
local Table = {}
local Maxplr = nil
TableNumber = 1
function Assign(Player)
if Table[TableNumber].Configuration.Occupied.Value ~= true then
print(TableNumber.." Occupied By ".. Player.Name)
Table[TableNumber].Configuration.Occupied.Value = true
wait()
Player.Character.Torso.CFrame = Table[TableNumber].CharacterSpot.CFrame*CFrame.new(0,2,0)
elseif TableNumber >= Maxplr then
TableNumber = 1
Assign(Player)
else
TableNumber = TableNumber + 1
print(TableNumber)
wait()
Assign(Player)
end
end
function PlayerAdded(Player)
repeat wait() until Player.Character ~= nil
wait()
local GetSpawn= workspace.SpawnPoints:GetChildren()
for i,v in pairs(GetSpawn) do
table.insert(Table,GetSpawn[i])
Maxplr = i
end
Player.CharacterAdded:connect(function()
Assign(Player)
end)
Player.Character.Humanoid.Died:connect(function()
Table[TableNumber].Configuration.Occupied.Value = false
end)
Assign(Player)
end
function PlayerRemoved(Player)
Table[TableNumber].Configuration.Occupied.Value = false
end
game.Players.PlayerAdded:connect(PlayerAdded)
game.Players.PlayerRemoving:connect(PlayerRemoved)
I have the print function on line 7, which tells me whom is being placed in what room. The Maxplr is max amount of rooms the game allows. For now, it's ten.
The first time, the script works 100% with the player spawning in their respective rooms.
1 Occupied By Player1
1 Occupied By Player1
2
2 Occupied By Player1
3
3 Occupied By Player1
Above is the prints I get after respawning each time. I have no idea in why it works the first reset and not the second, and so on. What I need to figure out is how to make sure it always returns them to the first unoccupied room, which should be 1. Help would be gladly appreciated!

3 comments
20:26:25.301 - Workspace.Auto Assign:29: attempt to index field '?' (a nil value)
I fixed the end) issue on line 28, however I am getting that Workspace.Auto Assign:29: attempt to index field '?' (a nil value) Error.
Yeah there were a couple of spelling mistakes (didn't test the code), are you still getting an error?