Hey I’m making a obby/death run styled game. So I need a random map choser. I’m not asking for you to do all of it. I’m just asking for an idea. And how I should do it without it lagging out. And an idea were the safest place to store all of these maps in.
Feel free to ask any questions.
The reason I am asking is because I am not a big Scripter or anything but can understand it.
To do this, you need to make a working round system. Then once you select the map, it should be something like this: (maps in ServerStorage)
local maps = game.ServerStorage.Maps:GetChildren()
local rand = math.random(1,#Maps)
local selectedMap
for i,v in pairs (maps) do
if i==rand then
selectedMap = v:Clone()
break
end
end
selectedMap.Parent = game.Workspace
Hope this helped The advantage with my system is that you don’t have to update the script every time you add a map, it’s relative.
local maps = {1,2,3,4}
local chosen = maps[math.random(1,#maps)]
chosen.Name = "ChosenMap"
chosen.Parent = workspace
for _, player in pairs(game.Players:GetPlayers()) do
player.Character.CFrame = workspace.ChosenMap.SpawnPart.CFrame
end
You should have a folder inside ServerStorage called “Maps”.
local Maps = game.ServerStorage.Maps:GetChildren() -- Gets the children of maps
local Rand = math.random(1, #maps) -- Picks a random number from 1 to the number of maps
Maps[Rand]:Clone().Parent = workspace -- Picks the random map by indexing it with the random number and cloning it into the workspace.
If you want to teleport the players, use this:
local Maps = game.ServerStorage.Maps:GetChildren() -- Gets the children of maps
local Rand = math.random(1, #maps) -- Picks a random number from 1 to the number of maps
local TeleportPosition = Vector3.new(0, 0, 0) -- This is the position you want to teleport the players.
local TeleportCFrame = CFrame.new(TeleportPosition) -- This is the CFrame you want to teleport players. You don't need to edit this, you only need to edit the TeleportPosition
Maps[Rand]:Clone().Parent = workspace -- Picks the random map by indexing it with the random number and cloning it into the workspace.
for _, Player in pairs(game.Players:GetPlayers()) do -- Loops through all the players in-game.
if Player.Character then -- Checks if the player has a character. Players might not have a character when they first join in to the game, or when their character is respawning.
Player.Character:SetPrimaryPartCFrame(TeleportCFrame) -- Sets the character's CFrame to the teleport CFrame. Basically moving the character.
end
end
ServerScriptService is where you would regularly store your regular scripts. Although it also works in Workspace, putting scripts in ServerScriptService just makes your game organised and easy to access. I’m pretty sure it’s safer to put scripts in ServerScriptService too, as it is not replicated to the clients.
No worries, if you’ve got no more questions relating to the topic of this discussion. Please mark the most appropriate answer as the solution, so other people who stumble upon this post can quickly find the solution. Thanks!