Randomly chosen round map!

Hello developers!
I’m making a game that has rounds and several maps.
The round system is already working. I only need a script now, that teleports players to a map randomly.
Every player has to go to the same map, which has been randomly chosen before the round starts.
The round system I have at the moment, teleports people to a brick. That’s what it’s supposed to do, but I want it to choose one of mutiple bricks I told it to choose from, and teleport people to there, the same thing needs to run every new round.

Scripts and my explorer

This is what my explorer looks like:
Desktop Screenshot 2021.05.16 - 19.32.32.81 Desktop Screenshot 2021.05.16 - 19.32.14.88

The Script in ServerScriptService:

local roundLength = 5 -- How long the round is in seconds
local intermissionLength = 5 -- How many seconds are inbetween the rounds

local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameAreaSpawn

InRound.Changed:Connect(function()
	if InRound.Value == true then
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameAreaSpawn.CFrame -- This part of the script of the script teleports people to a part called GameAreaSpawn. (The spawn on the map)
		end
	else 	 
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame -- This part of the script of the script teleports people to a part called LobbySpawn. (The lobby)
		end
	end
end)

local function roundTimer()
	while wait() do
		for i = intermissionLength, 0, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
		end
		for i = roundLength, 0, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Game: ".. i .." seconds left"
		end
	end
end

spawn(roundTimer)

.
The LocalScript in StarterGui

local Status = game.ReplicatedStorage.Status
local TimerDisplay = script.Parent.TimerDisplay

Status.Changed:Connect(function()
	TimerDisplay.Text = Status.Value
end)

I need a script that randomly chooses a part to teleport the players to. Every round, all the players in the server must teleport to a randomly chosen map.

Please note that I know close to nothing about scripting. The scripts and everything else you see has been made with the help of a tutorial and people here on the devforum.
Thanks for helping!

1 Like

I recommend you start by naming all the spawns the same thing. Then, put all of the spawns in a folder. I’ll call that folder “Teleports”.

Then, we need to create a script that gets a random spawn from that folder and moved the character to it.

Observe:

	local function spawnPlr() --creates a function that spawns players.
		local posFolder = workspace.Teleports:GetChildren() --classifies the folder containing the teleport locations.
		
		local randPos = posFolder[math.random(1, #posFolder)] --gets a random part in the Teleports folder and classifies it in a variable.
		
		--here, you'd have to define the player however your script does it, and then use this example: player.Character:MoveTo(randPos)
	end

--then we call the function when you want to move the character to the random spot!
spawnPlr()
1 Like

Okay, and like, do i have to put this somewhere inside the ServerScriptService script or do i need to create a new script?

well, do you have a script already made for this?

I thought I might have to edit something inside of here to make everything work.

Especially this part

!!!Make sure you put all of the teleport parts inside of a folder named “Teleports” in the workspace!!!

local roundLength = 5 -- How long the round is in seconds
local intermissionLength = 5 -- How many seconds are inbetween the rounds

local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local LobbySpawn = game.Workspace.LobbySpawn
local GameAreaSpawn = game.Workspace.GameAreaSpawn

InRound.Changed:Connect(function()
	if InRound.Value == true then
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			local posFolder = workspace.Teleports:GetChildren()
            local randPos = posFolder[math.random(1, #posFolder)]
            char:MoveTo(randPos.Position)
		end
	end
end)

local function roundTimer()
	while wait() do
		for i = intermissionLength, 0, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
		end
		for i = roundLength, 0, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Game: ".. i .." seconds left"
		end
	end
end

spawn(roundTimer)

The script above will move players to a random spot in the arena you’re making, but won’t teleport them back to spawn. It would be easier if you put a spawnpoint in the spawn map and killed the players when the event is over.

That could be done. One thing, I now get an output error from this part of the code:

Because we changed the location. What do I put here?

could you send me the error message?

Script - Roblox Studio 18-5-2021 14_01_10
@Expistic sorry that it took long, something in my room fell down and I had to pick it up.

1 Like

^^ Delete this line of code at the very top.

Error is gone, but I still don’t teleport to one of the bricks I’ve put into the folder.

Let me take a look really quick.

Do you think you can send a picture of ReplicatedStorage?

If you are interested in a video :slight_smile:

The blue blocks are the things i want to spawn to. They are in the teleports folder.

Sure!

^^^requested access to view the drive.^^^

Under construction seeking game - Roblox Studio 18-5-2021 14_14_26

Oops, ill fix that
Edit: should work now

local roundLength = 5 -- How long the round is in seconds
local intermissionLength = 5 -- How many seconds are inbetween the rounds

local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local LobbySpawn = game.Workspace.LobbySpawn
--local GameAreaSpawn = game.Workspace.GameAreaSpawn

InRound.Changed:Connect(function()
	if InRound.Value == true then
		for i, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			local posFolder = workspace.Teleports:GetChildren()
            local randPos = posFolder[math.random(1, #posFolder)]
            char:MoveTo(randPos.Position)
		end
	end
end)

local function roundTimer()
	while wait() do
		for i = intermissionLength, 0, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Intermission: ".. i .." seconds left!"
		end
		for i = roundLength, 0, -1 do
			InRound.Value = true
			wait(1)
			Status.Value = "Game: ".. i .." seconds left"
		end
	end
end

spawn(roundTimer)

here i changed the loop type from _, to i,

just wanna see if thats the issue here

Everything works now.
But. it teleports you to whatever part is closest to the player for some reason :grimacing: