How would I make a random map choser?

I’ve just removed the TeleportPosition variable and replaced the TeleportCFrame variable with the CFrame of the part.

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 TeleportCFrame = game.Workspace.TeleportPosition.CFrame -- This is the part where you would get teleported.

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.

Now it’s not cloning or is it because I haven’t configured the teleport yet?

my way is just having one part that constantly moves to different maps with CFrame so it randomly picks XD

So I use this script all the time make a script in serverscriptservice.
Now inside the script insert a module script.

Also make a folder inside Replicated Storage and put all the maps inside the folder(I’m naming it maps.)

Now type this script inside the module Script.

function module.SelectMap()
	local rand =
	local chapters = game.ReplicatedStorage.Maps:GetChildren()
	local choosedchapter = chapters[rand:NextInteger(1, #chapters)] -- this will choose any one map from the folder.
	return choosedchapter

if you want to teleport them to the map make a part inside every map and name it mapSpawn.(Type in module script)

function module.teleportPlayers(players, mapSpawns)
	for i, v in pairs(players) do 
		if v.Character then
			local character = v.Character
			if character:FindFirstChild("HumanoidRootPart") then
				local rand =
				v.Character.HumanoidRootPart.CFrame = mapSpawns[rand:NextInteger(1, #mapSpawns)].CFrame +, 10, 0)

Now go to your script and type this

local Round = require(script.ModuleScript)

local ChoosedMap = Round.SelectMap()
	local ClonedMap = ChoosedMap:Clone()
	ClonedMap .Parent = workspace
    ClonedMap .Name = "ClonedMap"

      if ClonedMap :FindFirstChild("mapSpawns") then
		Round.teleportPlayers(ClonedMap .mapSpawns())
		warn("Error no teleporot spawns") 

I just get a bunch of errors…

can you show me the output?

30 charss

I blurred the parts that are not part of it

1 Like

Sorry I didn’t put the whole script.
Now I have edited it.
Try now.

It’s red underlining module… In the module script

do you have the

local module = {} -- at the beginning 
-- and
return module -- at the end.

Also make sure it is not capitalized.

it red underlines the first function it isn’t shown in this picture but it is.

You’re returning the module before defining the SelectMap method; the return statement escapes the current scope and doesn’t allow any code after it to execute.

Oh so I should put the code in between?


@WildRagers I think you should watch this video.
Here @Alvin_Blox tells about module scripts in detail.
Or you could see the API reference of Module Scripts

Module scrips are very useful and makes your game easy to make.
It maybe hard to study module scripts at the beginning but it will be easier after time passes.

I didn’t they just gave it to me?

Not saying I don’t apreciate it.

Anyway I changed it. (30 chars)

That’s asking for scripts. You asked how to make it and somebody gave it to you that’s basically against the rules and classified as asking for someone to write a entire script.

No read my description of this post. Also let’s not break another rule and bring this to DM’s.

1 Like