Generating a level when player touchers a teleporting part

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?

Thanks :slight_smile:

Well you would start with this:

Once the object is touched, get the next level, which you can put in replicated storage and clone it, then put the new level into the workspace.

Have a part inside of the level, then move the players character to it.
Thats about it!

If you wish to move the character you can do this.

player.Character.PrimaryPart.CFrame = CurrentLevel.TeleportArea.CFrame

Hi,

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.

Its actually really simple!

local level = YourLevelHere
local newLevel = level:Clone()
-- or
local level = yourLevelHere:Clone()

then you would just do

level.Parent = workspace
2 Likes

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.

Oh FroDev beat me to it lol.

2 Likes

One thing to note is instead of doing game.Workspace:
Instead use just straight up workspace

2 Likes

Oh I just do game.Workspace out of preference, but yea workspace works

2 Likes

Thank you both!! I got it to work :smiley:

1 Like

Glad to hear, also you can go ahead and give the solve to FroDev, they answered with the same solution first.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.