Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a lobby script?

I made a script that when a player spawns, he will be transfered to the so-called Lobby baseplate. After a 10 second intermission, the players will be transfered to the positions of the random part of a map. After 5 minutes, they will return to Lobby once more.

I fixed the problems in the output but when I tried it nothing happened. My character didn't even go to the Lobby. Can someone tell me what's wrong? And, thanks in advance

This is the script:

print("Lobby Script Online...")
local lobby = script.Parent
local debounce = false
local teams = game:GetService("Teams")
local neutral = Instance.new("Team", teams)


if not game.Workspace:FindFirstChild("CurrentMap") then
	local model = Instance.new("Model", game.Workspace)
	model.Name = "CurrentMap"
end

neutral.Name = "Neutral" ; neutral.TeamColor = BrickColor.Gray()
lobby.Anchored = true

game.Players.PlayerAdded:connect(function(player)
	if not debounce then
		debounce = true
		player:WaitForChild("Character"):MoveTo(lobby.Position)
		player.TeamColor = BrickColor.Gray()
		player.Neutral = true
		debounce = false
	end
end)

while true do
	local players = {}
	 players = game.Players:GetPlayers()
	for _, v in pairs(players) do
		local maptable = {}
		math.randomseed(tick())
		maptable = game.Workspace:WaitForChild("CurrentMap"):GetChildren()
		players[_]:WaitForChild("Character"):MoveTo(
			maptable[math.random(#maptable)].Position)
	end
	
	wait(300)

	for p = 1, #players, 1 do
		players[p]:WaitForChild("Character"):MoveTo(lobby.Position)
	end
	
	wait(10)
end

1 answer

Line 19,33 and 40 , I don't understand how WaitForchild works, but every time I've used it, it's stopped my scripts.

Try just using

repeat wait() until player.Character

Also, MoveTo sometimes doesn't work well with Humanoids, try changing the Torso's CFrame:

--line 19 and 40
player.Character.Torso.CFrame = CFrame.new( lobby.Position )

--line 33
player.Character.Torso.CFrame = CFrame.new( maptable[math.random(#maptable)].Position )

One last thing, since you get the children of players on line 28, you don't need to define a table on line 27.

You can also use the same method on line 39, as you do on line 29 ( for in pairs(players) do )

This discussion is preserved as it was. New answers, comments, and votes are closed.