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:
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!
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()
!!!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.
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)