Hello everyone, it’s been a while since I’ve used the devforums, but I just needed a little bit of help. To preface all of this, I am not very experienced in scripting. So, I am working on a project, and with this said project, when a player touches an invisible part (or sometimes clicks), it teleports them onto another ‘level’. It’s not randomly generated. The way I have it set up now is very inefficient, where the different levels are in the same area. However, some levels are outside of buildings, so I don’t want players to see the other levels floating around. Is there a specific resource where I can read on how to accomplish something where the level is only generated into the workspace when the player is teleported to it? Think something like, maybe Arsenal?
I created a new baseplate in order to test to see if I could make this work. I added a part named “level 1” and “level 2”. Level 2 was put into ReplicatedStorage while Level 1 remains in the Workspace. There is a red part that, when clicked, would cause Level 2 to generate into the Workspace, thus generating the “level”. However, I’m unsure how to clone the 2nd level from replicatedstorage into workspace. i apologize, like i said, im not much advanced in scripting.
Like @FroDev1002 said, you should store the levels in ReplicatedStorage then clone them and parent them to Workspace for the player, but make sure that either all players go to the same level at the same time, or that you’re loading the levels in locally, and I recommend having the levels far apart anyway, so that people don’t see other people in different levels floating around on or clipping into parts that aren’t visible for some people.
To clone and put the levels in, you can just have each level in a folder in ReplicatedStorage, then do something like this:
Code
local level1 = game.ReplicatedStorage.Level1
local level2 = game.ReplicatedStorage.Level2
local levelLoaded = nil
function loadLevel1()
if levelLoaded then
levelLoaded:Destroy()
end
local level1Clone = level1:Clone()
level1Clone.Parent = game.Workspace -- or just workspace instead of game.Workspace
levelLoaded = level1Clone
end
function loadLevel2()
if levelLoaded then
levelLoaded:Destroy()
end
local level2Clone = level1:Clone()
level2Clone.Parent = game.Workspace -- or just workspace instead of game.Workspace
levelLoaded = level2Clone
end
Then just call the functions to load those levels.