I am currently working on a lobby for my game. The lobby is a GUI lobby rather than a physical lobby. The problem with my script is that after the first 2 rounds, it starts teleporting players to the wrong spot. For example, if a player has the Bloxian role, they teleport to where the nightguard is supposed to be. And the nightguard doesn’t teleport to where he should be at all, but he can’t move or jump. The only hint I got to the problem was an error called “Sit: This seat is occupied”. However, when I investigated, the seat was not occupied at all cause occupant was set to nil. What is the problem here?
Script:
Time = game.ReplicatedStorage.Remotes.Time
intermissionBegan = game.ServerStorage.Info.IntermissionBegan
assign = game.ReplicatedStorage.Remotes.AssignRoutes
gameOn = game.ServerStorage.Info.GameOn
bloxianTeleports = workspace.EmptyHouse.BloxianTeleports
hallwayTeleports = workspace.EmptyHouse.BloxianTeleports.HallwayTeleports
doorTeleports = workspace.EmptyHouse.BloxianTeleports.DoorTeleports
startingLocations = workspace.EmptyHouse.BloxianTeleports.StartingLocations
reset = game.ServerStorage.Binds.Reset
makeInvisible = game.ReplicatedStorage.Remotes.MakeLobbiesInvisible
binds = game.ServerStorage.Binds
game.Players.PlayerAdded:Connect(function(player)
player:WaitForChild("PlayerGui"):WaitForChild("Lobby").GameLobby.Visible = true
end)
game.ServerStorage.Info.NumberPlayers.Changed:Connect(function(change)
if change >= 2 then
if not intermissionBegan.Value then
if not gameOn.Value then
beginTimer()
end
end
else
Time:FireAllClients("Waiting For Players...")
end
end)
function beginTimer()
intermissionBegan.Value = true
local seconds = game.ServerStorage.Info.Time.Value
print("Timer Began")
for i = seconds, 1, -1 do
if game.ServerStorage.Info.NumberPlayers.Value < 2 then
intermissionBegan.Value = false
Time:FireAllClients("Waiting For Players...")
return
else
Time:FireAllClients("Intermission - "..(tostring(i)))
wait(1)
end
end
gameOn.Value = true
Time:FireAllClients("")
beginGame()
end
local function giveRoles()
local num = 1
local players = game.Players:GetPlayers()
local random = math.random(1, #players)
local routes = {
{startingLocations.Bloxian1Start, bloxianTeleports.Bloxian1["Bloxian1[2]"],
bloxianTeleports.Bloxian1["Bloxian1[3]"], bloxianTeleports.Bloxian1["Bloxian1[4]"],
hallwayTeleports.Hallway1, doorTeleports.Door1},
{startingLocations.Bloxian2Start, bloxianTeleports.Bloxian2["Bloxian2[2]"],
hallwayTeleports.Hallway1, doorTeleports.Door1},
{startingLocations.Bloxian3Start, bloxianTeleports.Bloxian3["Bloxian3[2]"],
hallwayTeleports.Hallway2, doorTeleports.Door2},
{startingLocations.Bloxian4Start, bloxianTeleports.Bloxian4["Bloxian4[2]"],
bloxianTeleports.Bloxian4["Bloxian4[3]"], bloxianTeleports.Bloxian4["Bloxian4[4]"],
hallwayTeleports.Hallway2, doorTeleports.Door2}
}
for _, plr in pairs(players) do
if players[random] ~= plr then
plr:WaitForChild("Info").Role.Value = "Bloxian"
plr.Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
plr.Character:WaitForChild("Humanoid").JumpPower = 0
plr.Character:WaitForChild("Humanoid").WalkSpeed = 0
assign:FireClient(plr, routes[num])
num = num + 1
print("Bloxian Placed")
else
plr:WaitForChild("Info").Role.Value = "Nightguard"
plr.Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Viewer
if workspace.EmptyHouse.Chair.NightSeat.Occupant == nil then
workspace.EmptyHouse.Chair.NightSeat:Sit(plr.Character:WaitForChild("Humanoid"))
else
print("SEAT IS OCCUPIED")
end
plr.Character:WaitForChild("Humanoid").JumpPower = 0
print("Nightguard Placed")
end
end
num = 1
print("Roles Given")
end
function makeLobbiesInvisible()
wait(0.1)
makeInvisible:FireAllClients()
workspace.EmptyHouse.Lighting.Power.LowerInPower.Disabled = false
workspace.EmptyHouse.Lighting.Clock.Time.Disabled = false
print("Lobbies made invisible")
end
function beginGame()
giveRoles()
makeLobbiesInvisible()
end
function turnOnLights()
local lights = workspace.EmptyHouse.Lighting:GetChildren()
for _, light in pairs(lights) do
if light.Name == "Light" then
light.PointLight.Enabled = true
light.Material = Enum.Material.Neon
end
if light.Name == "DoorButton" then
light.Material = Enum.Material.Neon
light.ClickDetector.MaxActivationDistance = 32
end
if light.Name == "SecurityLight1" or light.Name == "SecurityLight2" then
light.PointLight.Enabled = true
light.Material = Enum.Material.Neon
end
end
binds.ShutDown1:Fire()
binds.ShutDown2:Fire()
print("Lighting reset")
end
reset.Event:Connect(function()
print("Resetting...")
turnOnLights()
intermissionBegan.Value = false
gameOn.Value = false
for _, plr in pairs(game.Players:GetPlayers()) do
plr.Character:WaitForChild("Humanoid").Sit = false
wait(0.1)
plr.Character:MoveTo(workspace.SpawnLocation.Position)
plr:WaitForChild("Info").Role.Value = ""
end
workspace.EmptyHouse.Lighting.Power.LowerInPower.Disabled = true
workspace.EmptyHouse.Lighting.Clock.Time.Disabled = true
workspace.EmptyHouse.Lighting.Power.Percentage.Value = 100
while game.ServerStorage.Info.NumberPlayers.Value < 2 do
Time:FireAllClients("Waiting For Players...")
end
if game.ServerStorage.Info.NumberPlayers.Value >= 2 then
beginTimer()
end
end)