Local Environments

Couldn’t find anything related to this on the forum (or perhaps I didn’t use correct search terms?).


I’m asking for assistance in how I should setup environments that only a specific player can access.

For example, if I make an apartment system and I want a player to access their apartment by teleporting to it, how do I make sure every player’s apartment is unique to them and doesn’t conflict with another player’s room? I can’t have one apartment in Workspace and teleport the player to that because then every player would teleport to the same place!

I was thinking of having a new structure cloned somewhere when a player joins, but how I get this to efficiently work?

1 Like

Like a VIP room but instead of only letting gamepass owners, you only let people with a specific username/id, yes?

It’s a place everyone can teleport to, but when they arrive, they’ll only be there by themselves (basically their own private area)

You could put the area into ReplicatedStorage then add a local script (obviously one that specifically works on the localplayer not just a localscript) then make it so it gets moved into the workspace from rep?

That’s similar to what I was thinking, but my main issue comes from how I would place the cloned place into Workspace, since if I put them in the same spot, everyone could see each other (teleporting players via LocalScript replicates their character position to the server)

Add duplicates depending on the max players (it would not lag as it’s in replicated) then make it so whenever someone leaves, it gets moved back into replicated, then when someone joins, it’s put into workspace again.

That could work; once I finish the setup, I’ll post what I did (for anyone reading in the future)

Edit: I did what pulse_tech suggested with creating duplicates based on max players

local original = ModelInstance -- the original Model Instance that will be copied for each player
local size = original:GetExtentsSize() -- get the Vector3 size of the area (used for positioning)
local posOffset = 5 -- distance between each private area
local lastModel = original -- the last model created

for i = 1, players.MaxPlayers do
	local clone = original:Clone() -- create a new area
	clone.Name = '0' -- the name is associated with the UserId of the player who will be teleported there
	clone.Parent = workspace -- add the area to workspace
	
    -- position the copy in workspace away from the last created model
	clone:PivotTo(lastModel:GetPivot() * CFrame.new(0, 0, posOffset * size.Z))
	lastModel = clone -- set the last model created to the current model
end

(This of course is only a snippet of what I did, but it’s the core element)

Making all the players invisible may have been a better solution, but for my specific use case in-game, I don’t believe it would’ve worked

1 Like

Actually there is a simpler way; you could just make a localscript that deletes all the other players? Or is this some kind of thing where it’s only one room?

1 Like

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