Hello. So I already made a script where it prints the map that is chosen randomly. But I don’t know how to load the map that is chosen. (There is no need for me to show the script because my script work fine.) Anyway thanks!
Simply change the parent of the map to workspace.
local clonedMap = selectedMap:Clone()
clonedMap.Parent = game.Workspace
Just change selectedMap to whatever your variable is.
You just need to clone it, that’s all!
You can have your maps stored in a storage container, outside of workspace.
Then, you can clone the map and set its parent to workspace.
For example:
-- An idea on locations of things
local Map = path.to.map
local CurrentUsedMaps = workspace.Maps
-- To clear out the maps
CurrentUsedMaps:ClearAllChildren()
-- To clone the map
local Clone = Map:Clone()
Clone.Parent = CurrentUsedMaps
Pretty basic, but you get the idea.
No I mean like the script randomly prints a map name. But I want it so that loads that map into workspace
Where exactly are you trying to load the map from?
serverstorage (30 charsssssssss)
Pretty much what was mentioned above.
If you really want to, just name the maps the same as your map name (if you haven’t already) so you can do something like this:
local RandomMapName = "ExampleMap"
local Map = ServerStorage:FindFirstChild(RandomMapName)
Shouldn’t you check which map it is before putting it to workspace?
I assume you’ve already got a system for choosing the map, so as long as you’ve chosen the map, there shouldn’t be a need for checking it (unless I’m misunderstanding you).
You could add a failsafe here:
if Map then
This isn’t extremely necessary but in the event that the :FindFirstChild() finds no map with that name, you can control what happens with that error.
A breakdown of the script I sent you in my last post:
local RandomMapName = "ExampleMap" -- placeholder, replace with how you get the map name, you said you outputted it, so you must've got it somewhere
local Map = ServerStorage:FindFirstChild(RandomMapName) -- search ServerStorage for the map name. If RandomMapName was ExampleMap, it would search ServerStorage for an instance called ExampleMap
And combined with the one I sent a few replies back:
-- An idea on locations of things
local Map = path.to.map
local CurrentUsedMaps = workspace.Maps
-- To clear out the maps
CurrentUsedMaps:ClearAllChildren()
-- To clone the map
local Clone = Map:Clone()
Clone.Parent = CurrentUsedMaps
Oh I think you are making mini game, I’m gonna just say I would store maps in lighting.
Also if you don’t know how to load map which is choosen then I’m gonna show you a example.
local ChoosenMap = math.random(1,HowManyMapsDoYouGot)
if ChoosenMap == 1 then
game.Lighting.Map1:Clone().Parent = game.Workspace
end
if ChoosenMap == 2 then
game.Lighting.Map2:Clone().Parent = game.Workspace
end
Hope this helped.
Edit: changed :Parent to .Parent
Lighting isn’t a storage container, you shouldn’t suggest using it for a few reasons: one of them being clarity. ServerStorage, on the other hand, is fine to store maps in.
Also, your method is extremely verbose.
As I mentioned before, you can just find the map by the name that the OP has already somehow generated, judging by the content at the top of this topic.
local RandomMapName = "ExampleMap" -- placeholder, replace with how you get the map name, you said you outputted it, so you must've got it somewhere
local Map = ServerStorage:FindFirstChild(RandomMapName) -- search ServerStorage for the map name. If RandomMapName was ExampleMap, it would search ServerStorage for an instance called ExampleMap
For me lighting is fine, you should stay.
Sorry for recommending you.
All these replies are over complicating things. This code is what I would use for a random map choice:
local Maps = [MapContainer]:GetChildren()
MapSpawn.Event:Connect(function()
local ChosenMap = Maps[math.random(1,#Maps)]:Clone()
workspace.Maps:ClearAllChildren()
ChosenMap.Parent = workspace.Maps
end)
It gets all children of the map storage container, such as serverstorage, and gets a random map with math.random. This can error if the map is removed from the container, but I doubt you’re removing and adding maps while the game is running, but if you are, just change the code to have local Maps = [MapContainer]:GetChildren()
in the event connection.
Wait what is the function at line 3 for?
when you want to spawn a map in, placeholder function.
Oh ok thanks! (30 charsssssssss)