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.
end
end
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 = Random.new()
local chapters = game.ReplicatedStorage.Maps:GetChildren()
local choosedchapter = chapters[rand:NextInteger(1, #chapters)] -- this will choose any one map from the folder.
return choosedchapter
end
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 = Random.new()
v.Character.HumanoidRootPart.CFrame = mapSpawns[rand:NextInteger(1, #mapSpawns)].CFrame + Vector3.new(0, 10, 0)
end
end
end
end
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())
else
warn("Error no teleporot spawns")
end
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.
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.
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.