Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Multiplace game help ?

earlier i posted a Question on teleporting and asked "Does the place your teleporting to need to be active" and i got the answer, but how do games like Speed Run 4 and Phantom Forces have different maps without teleporting the player ?

2 answers

✓ Accepted answer

These games do not use multiple places. They simply load the maps in by cloning data and extracting the children into a specific directory in Workspace.

For example:


local maps={	--Make an array to store all of the maps you want to load
	game.ReplicatedStorage.map1;
	game.ReplicatedStorage.map2;
}
local mDir=game.Workspace.Map --Directory in the workspace, in which the map would be contained

function loadMap(id) --A function to load the map

	mDir:ClearAllChildren() --Erase any previously existing map.

	local id=id or math.random(1,#maps) --Define the mapID if not manually defined
	
	local n=0 --Anti lag number
	for _,c in pairs(maps[mid]:GetChildren()) do --For loop to get the contained map objects
		n=n+1 --Add to our magic number
		c:Clone().Parent=mDir --Clone the part into the map directory
		if n % 2 == 0 then game:GetService("RunService").Stepped:wait() end --If n is even then yeild, this is to not freeze up when cloning a map with a ton of children
	end
end

loadMap() --This would load a random map
loadMap(2) --This would load map2

Sources: math.random, Modulus operator (%), Clone, for in pairs, Get children, Clear all children

2 comments

0

Hey, Thanks so much !!

0

No problem! If you have any questions on how things work, just ask!

I think I know what you mean and it's also pretty simple. One common way is too, put all your parts into a model and then have that model stored inside ServerStorage or Lightning. When you got this setup then you can simply just use a script that removes the model inside workspace and then clone of the maps from where we located them. If you have more models inside the storage area than your maps use my method where I add a BoolValue inside of the model and I often name it "isMap".

Something like this for example

local storage = game:GetService("ServerStorage") --access ServerStorage or Lightning if you use that
local storageItems = storage:GetChildren() --return the children of storage in a table
local maps = {} --here all of the maps will be stored so we can find a ranomd map
local currentmap --placeholder for the map in use

for i, v in pairs (storageItems) do --loop through all storageItems
	if v:IsA("Model") and v:FindFirstChild("isMap") then --we check if object "v" is a model and if it got isMap inside of it, so we know for sure it's a map
		table.insert(maps, #maps + 1, v ) --table.insert got three arguments, first one is which table you want to add something into, the second one is where in the table(if it would be in one, two and so on), in this case, we put it according to how many maps is stored inside of the table. So if zero maps are inside of it insert our object in the first slot (0+1). The third one represents the object which will be inserted.
	end
end

function newMap()
	if currentmap ~= nil then --checks if there is a map in use
		currentmap:ClearAllChildren() --clear the map in use
	end
	local randomMap = math.random(1,#maps) --pick a random number according to how many maps you got
	local mapClone = maps[randomMap]:Clone() --clone a random map
	mapClone.Parent = game.workspace -- put it in workspace.
	currentmap = maps[randomMap] --assign the map in use
end

newMap() --execute the function

Sources: Function, Math.random, GetChildren, Table, table.insert, Clone, For loop, in pairs

This discussion is preserved as it was. New answers, comments, and votes are closed.