I am building an obby where you will have special maps for each set of stages. I am hoping for support in ReplicatedStorage, as some of these maps are very large, and I wish to store them until I am teleported to them. To clarify, when I touch a specific part, I am teleported (Do not need script for this) to a place in the map, and when I am teleported there, I want the map to be there. And when I teleport away, I wish for the map to also disappear.
Thank you for reading, and I hope I find a solution.
It depends on how you want the map to load in. Do you want it to show up for everyone in the game if someone is on the stages inside a map. Or only the person who is on those stages?
Ok so Iām going to assume that your teleport pad script is directly underneath a part and it is a global script. To make it only show up for the person on the stage the loading in script will need to be a local script. So you will need to be introduced to the world of Remote Events!
Remote events are way cool, they are a way for server scripts and local scripts to communicate and tell the other to do stuff.
Drop a remote event inside ReplicatedStorage and rename it to āLoadMapā. And drop a local script inside starter player scripts.
From the server(Script under the part) you can Fire to the client(local script inside starterPlayerScripts).
-- These two will go at the top of your script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:FindFirstChild("LoadMap")
-- This next two lines will go right before where you teleport the player.
local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- hit is the part that triggered the .Touched function.
Event:FireClient(Player, "NextMap", "CurrentMap") -- NextMap should be replaced with the name of the next map you are going to load in. CurrentMap should be replaced with the Map inside workspace you want to destroy.
Now inside your local script you put the following:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:FindFirstChild("LoadMap")
Event.OnClientEvent:Connect(function(CreateMapName, DeleteMapName)
if ReplicatedStorage:FindFirstChild(CreateMapName) then
local Map = ReplicatedStorage:FindFirstChild(CreateMapName)
Map.Parent = game.Workspace
else
print("No map named " .. CreateMapName .. " inside ReplicatedStorage")
end
if game.Workspace:FindFirstChild(DeleteMapName) then
game.Workspace:FindFirstChild(DeleteMapName):Destroy()
else
print("No map inside workspace named " .. DeleteMapName)
end
end)
Try to implement this if you have any questions on how or why this works, or if you struggle to implement it let me know!