I need a script that chooses a random map
I know it has something to do with math.random
but I just can’t successfully make it choose a map and drop it into workspace
properly.
I need a script that chooses a random map
I know it has something to do with math.random
but I just can’t successfully make it choose a map and drop it into workspace
properly.
local mapstorage = --where the maps are stored:GetChildren()
local mapnumber = math.random(1, #mapstorage)
mapstorage[mapnumber]:Clone()
im guessing it’s something related to something like this, i don’t know haven’t did something like this
Create a array of maps and get a random number between 1 and the amount of items in the map array, use that number to index (get) a random map from the array and drop it to workspace
Can I edit it to this?
local mapstorage = --where the maps are stored:GetChildren()
local mapnumber = math.random(1, #mapstorage)
local mappicked = mapstorage[mapnumber]:Clone()
mappicked.Parent = workspace
why not lol you’re correct forgot to parent it lol
Okay, well thanks for helping me!
Step1: Make Folder in ServerStorage called ‘Maps’.
Step2: Make map.
Step3: Add new Folder and name what you want!
Step3: Bring all map Folders to the Maps Folder.
Step4: Make new Script in ServerScriptService.
And script like:
local MapsFolder = game.ServerStorage.Maps
local Intermission = 10
local PlayTime = 10
local SpawnedMapFolder = Instance.new("Folder")
SpawnedMapFolder.Parent = game.Workspace
while wait(Intermission) do
SpawnedMapFolder:ClearAllChildren()
wait()
local PickedMap = MapsFolder[math.random(1,#MapsFolder:GetChildren())]
PickedMap:Clone.Parent = game.Workspace
wait(PlayTime)
end
I forgot clearing before map. But I edited
SpawnedMapFolder:ClearAllChildren()
(A bit of a cleanup of the code:)
local Location = game.ReplicatedStorage.Maps:GetChildren() -- Or where ever else it's located!
local function ChooseMap()
local Map = Location[math.random(1, #Location)]
local NewMap = Map:Clone()
NewMap.Parent = workspace
return NewMap
end
local GetMap = ChooseMap() -- Since the function returns the map, we can utilize that information here.
GetMap.Name = "" -- Whatever to name it!
GetMap.CFrame = workspace.MapLocation.CFrame -- Add a part in workspace named MapLocation, and place it where the center of the map should be!
You can keep using the ChooseMap function as many times as you want (for cleaner results), and edit the information via the variable below it.
Hopefully this helped you!