Best way to make singleplayer/player specific regions?

Hello!
I’m a pretty new dev on Roblox who’s coming from having experience in Java, so I’m trying to get the hang of how Roblox and Lua coding works. I’m getting used to the syntax, but I’m admittedly still trying to understand how Roblox handles worlds better, so I figured I’d ask for help on here.

Is there a good way to create localized/singleplayer worlds on a per-player basis, so for example, have a main town hub where everyone spawns in, but from there each player can leave to their own house/farm/etc?

I’d prefer not to have multiple players’ farms in a single area, since my current idea for optimization was to have one area for each player, and spawn in any extra parts the players might need to access out of view of the main map (so, for example, when the player enters their area from the town, they’d come out into the farm. If they enter the house, the house interior model would be spawned in behind the farm area, with the camera locked so they can’t turn around and see the farm area behind them). This would enable me to swap different sub areas in or out as needed, without requiring each player to have multiple areas to their name. However, due to the large variability of size in the pieces I’d be spawning in, that might make it difficult to place multiple players in a single area without having to put them massively far apart (unless there’s an easier way to do that without them seeing each other from the farm area?), and it means I’d have to add in a lot more code to make sure each player is at the proper area in the first place. I also can’t stack players apartment-style-- since the world is supposed to be open to the sky.

Alternatively, I’m wondering if it would be possible to reserve a certain number of empty worlds on a per-server basis, with a maximum number matching the max number of people on the server. Then, when a player joins, one of these worlds is designated for them, and when they leave that designation is removed. This would alleviate the issue of creating a new world for every single player, and would still make it reasonably easy for me to differentiate between whose house is where. I could also still spawn in set pieces in the secret back area behind the farm as needed, regardless of their size.

If possible, I’d also like to make it so that friends can visit the player’s world-- without being able to build there or anything. This wouldn’t require any transfer of ownership-- I’d just have to get them to the player’s farm in the first place. I have a fairly good idea of how to allow/disallow access to sub areas from there, so the question would just be making it so that someone can visit another player’s region.

The issue is that I’m not sure how to go about that. I know Roblox has a “place” system, though admittedly I’m still trying to figure out how that works. From what I imagine the town would qualify as the “starting place”, and each player world might need to be a new place as well? But it seemed like places were pre-set and based off an ID, so I’m not sure if there’s a way to easily connect them to a player. I’m also not sure if they have their own player caps, or if they’re connected to the server-- for example, I’ve seen games that transferred people to an entirely different game, and so when you spawned in, there were totally different people than those on your original server. If places work the same way, and count as their own separate servers, then I’m not sure my second method of having empty worlds would work too well, since people could be teleporting in from different servers. If places are still locked to the players on each server, though, static places might work just fine.

I’ve been poking around on the dev forums and elsewhere on the internet, but the questions I’ve seen about player housing have mostly involved storing data (i.e. if a player places a chair, how do you save its position/rotation etc.). I think I’m pretty clear on that aspect of it all-- it’s just getting them to their unique place in the first place where I’m unsure. I can’t say I’ve tested this out much because I’m frankly unsure of how to proceed.

Does anyone know how a system like this might be possible, and if my methods for going about it sound viable or if I should be trying something different?

Thanks, and have a great day!

3 Likes

In the same game or using places?

I’m not sure-- that’s part of what I’m trying to figure out. I want to go about this in the most efficient way possible. I was thinking I’d use places, but if there’s another way to do this that might be more efficient, I’m all ears.

Roblox has scripting containers called LocalScripts which run on the client compared to to the server. And Roblox’s server to client model only replicates a very small amount of things performed on the client to the server. For your application using a LocalScript would allow each client to have different workspaces loaded in. The only issue with this is LocalScripts are visible to the client and thus to exploiters. So you just need to be careful with how much code you leave to the client to use. To make the script more secure you can put most of your main code on a server script that uses RemoteEvents to send data to LocalScripts that will do the final rendering changes for the player.

You can use “universes” as worlds, you’d have the main universe which will be your “spawn”.
You can create places for player worlds/farms like hypixel skyblock if you know of that using CreatePlaceAsync AssetService | Documentation - Roblox Creator Hub
I’ve never really tried what you’re trying to do but I did plan on making something like that, goodluck!

You said you were coming from minecraft, I’m not sure how different it is when it comes to server and client communication with roblox and minecraft but when I tried to me they seemed pretty different, so watch out for that as well.

Did you consider Reserve Servers? Since CreatePlaceAsync seems to create a seperate place for each player which seems like it would get messy after a few players created “universes”.

I’ve been messing with LocalScripts some for camera functions, so I’m starting to get the hang of using those. I thought about the idea of using them to make stuff only load on the client, but the security risks are definitely my biggest concern. I was trying to read up on how easy they are/aren’t to hack, and it sounded as if the biggest issue was the possibility of people using them to call events on the server, so that might still be an option. I have to do stuff like camera changes on the client anyway, but that’s less critical if people try and tamper with it.

This is very much the sort of thing I was thinking! Is there still a concern with not being able to delete places created with CreatePlaceAsync? I saw quite a few topics about people struggling with that when I was researching, which does make me wary. If it works well, though, it does sound quite a lot like what I’m trying to do.

If I do get this working, feel free to hit me up if you do try and go about the same! I’d be happy to share my findings.

Oh yeah, this is significantly different from Minecraft. Thankfully Roblox’s server/client communication has been a lot more straightforward, at least imo.

I’m not actually aware of what Reserve Servers do. This is the first I’ve heard of them :sweat_smile: I could look into them though!

And yeah, that’s another reservation I’ve had. Are there any concerns with creating separate places for each player, or is that not an issue?

Yeah, as @xZylter said, reserve servers would be much better than createplaceasync.
Creating a new place for each player is fine since games that also have 1 player as max players exist and some have a lot of players.

There is nothing wrong with 1 player servers as long as when the player finishes from that server it’s gone which is most likely the case when using reserved servers, though keep in mind that no load balancer can handle shifting millions of people at once so consider making a queue system of some sort as well.

Also for letting people join your reserved server you can do something like the following : Starting a reserved server session that friends can join anytime - #6 by Corecii
(Though the user that wrote that seems to have a lot of bad practices in the code so I wouldn’t really port it 1:1, instead make your own version under the same idea, probably because it was old)

I’m researching reserve servers now. So if I’m understanding correctly, it basically transfers people to a server with only one member? Does it copy the existing server and place, or can I transfer people to a totally new world? I.e. starting town is multiplayer, but upon clicking “go home” the player gets whisked off the server and to their own world? Will it be an empty copy of the starting town, or can I set them to spawn directly into the farm? How easy is it to send them back to a multiplayer hub?

Trying to understand how it all works, but this sounds real promising. I can always save variables (i.e. the state of the farm) to a player, and update whichever server they load into accordingly, so…

Well, the main concern for exploiters is the data being sent to the server that the client has tampered with by modifying scripts. You should never trust the client to do what you’ve made it do. So I would make sure you don’t do the following:

  1. Don’t use RemoteFunctions for Server > Client > Server communication because the client can force their local scripts to not return a value to the server which is yielding so no more activity on that thread can occur. You can still use Client > Server > Client communication with RemoteFunctions.

  2. Double-check the variables sent by the client. You can use the client to do a primary check for data on the client and if it returns true, correct, etc send it to the server to reevaluate and give the final say.

Reserved Servers are the same game place but they’re “private sessions” so to answer you, no it won’t be empty, you’d have to do that by code if I am understanding them correctly.

I just wanted to follow up on @UWURAWRZDAD’s post and say that basically a reserve server once created can always be joined by using the same ID that it gives when first created. So if you use the DataStoreService you can save that ID to the reserve server to that player and that can then be shared to their friends to join their world.

1 Like

I believe looking into the TeleportService might be a start for you. While this does not address the concern of:

it would still be something to look into. Using TeleportService would allow you to reserve a server within your Game Universe to specific areas and each place could have its own feature such as your farms. The following code would help you achieve this (it is not perfect and just typed off the head sorry for any mistakes).

local TeleportService  = game:GetService("TeleportService")
local ReservedServer = TeleportServce:ReserveServer(PlaceID) --- PlaceID is the place you are wanting to teleport a player to within your Game Universe

This would reserve a place for the player and teleport them to it. I believe this could be done locally or on the server, but I haven’t used the TeleportService in a while. I possibly believe that you could solve your problem with having other players teleport here by using the MessagingService or whatever it is called (I’ve never used it). I do however know that you would be able to send data or messages across servers and places (I believe). This said, when teleporting the player using the TeleportService and ReserveServer, you would have to do something like:

TeleportService:Teleport(ReservedServer, player, Data) ---Data is not required

I believe you could pass the ReservedServer ID into the data and use MessagingService to pass it to a player (most likely friends I would assume or make it a global teleport I don’t know) which would allow the player to use the same Server ID in the TeleportServce:Teleport().

As I finished typing this you responded to @UWURAWRZDAD, so if I am wrong or need correction either them or @xZylter could help correct me. To answer you there are a couple things that could be done with ReserveServer. Reserving the server of the Starting Place (the hub) would mean it would copy what was in that place, which would include your town. However, if you make a sub-place and reserve a server of that place, it would be whatever you added in that place (buildings, code, etc.). If you wanted to make a dedicated area for just a player’s farm that is separate from the town, I believe the second option of a sub-place might be more reasonable whereas the first option seems more like a VIP server type of teleport.

EDIT: I know some of this has already been addressed but I wasn’t going to remove all of that. Sorry for the long read.

2 Likes

Follow up to this :
The main practice in Roblox is just : Do not let the client tell the server what to do, always have the server in control and checking for the clients activity for any unidentified behavior.
As far as your game idea goes on, I doubt it’ll be that exploitable anyways, assuming you’re going with something like the minecraft vibe then EVERYTHING and I mean everything has to be confirmed through the server because other clients have to see it. It’s wonderful!! :smiley:

Simple checks like having a “current session inventory” for each player is something that’s supposed to be common in games like these, so I’m assuming you’ll have that as well, and checking for stuff couldn’t be any easier!

Client wants to buy x → client sends a remote request to the server asking to purchase → server checks the client’s money and sees - Does the client have enough or not? if not then do nothing else purchase.

It’s so simple and amazing isn’t it?!

Also another thing about reserved servers, you can send with the player’s teleport data something like “Town” or “Farm” and on the server you check for that, if town is sent then load the player’s town in that game, if farm is sent them load the farm.

To check if a server is a reservedserver all you have to do is look at the following :

local isReserved = game.VIPServerId ~= "" and game.VIPServerOwnerId == 0
2 Likes

I believe the Town is more like a hub and not a personal area per player. I may have misread something and let me know if so. If the Town is supposed to be a hub, I think reserving a server specifically for farms is a better idea. If the town is per person, you could accomplish what you’re looking for through switching between types (Town, Farm, etc.) on the reserved server.

However, from this method, you would have to reserve a new server every time you wanted to switch or have the server remove and place the different area (Remove the town and place the farm). This could produce some like depending on how many parts or buildings that would have to be removed and placed.

This said, what he said about having the server handle the data is correct. The more you can accomplish handling on the server is better for game security.

1 Like

Wow, thank you guys so much for the detailed replies! This has given me a lot to go off, and I think I’ve got a much clearer idea of where to start now :smiley:

If I’m understanding this correctly, then using the teleporter service to send someone to a reserved server and a specific place within that would fully handle my concern-- I could build the base farm as a “place” and then modify it according to whichever player reserves the server. Then, when the player goes back to the town place, I could use the teleporter service to send them back to a normal server. Right?

Thank you guys again for all your help! I really appreciate it!

If you give me 10 minutes I’ll be able to get onto my computer and provide better examples. I’m doing this all from my phone so it is kind of hard. You’re welcome for the help!

Well you would need some extra code in the game for the server to determine if it is a reserved server or a normal server. To determine this use this code…

local isReserved = game.VIPServerId ~= "" and game.VIPServerOwnerId == 0

And I suggest you save all player data to a DataStore since that is Roblox’s method of retrieving player data from previous times they played the game.

Thank you so much! It makes sense that you’d have to check, but I’m very glad to know it’s possible! I’ll have to start playing around with it and testing things out, but I think I know what to do now :slight_smile:

Haha! It did say be detailed, soooo xD
And thank you! I’m happy to be here!

Oh my goodness, that is quite a rarity! Well hello to my join date buddy! xD

Okay. So I am now on my computer and will be able to help with more code and whatnot.

Firstly to address @xZylter. You don’t necessarily need to determine if the server is reserved or not to make a “Farm” specific world. You would be able to accomplish the same thing with two different places in your game universe. To see what I mean look at this image (it is a gyazo link for those of you who will decide to question it). To add a place just go into Studio > View Tab > Game Explorer > Right Click the Places Folder.

I was about to type a lot of code with images and the like, but I remembered about the API Reference page for TeleportService:ReserveServer. This is probably the code you should base it off if you want to go about this. One of the prior posts mentioned datastores and this is how I would do it. The best thing about using datastores is you would possibly be able to figure out a way to get the code out of a players datastore and let other uses teleport there but I am not sure. The other thing about that link is that is what they are referencing for the code below.

local isReserved = game.VIPServerId ~= "" and game.VIPServerOwnerId == 0

In the code on the webpage it says:

if msg == "reserved" then -- Aha, that's our cue
	TS:TeleportToPrivateServer(game.PlaceId,code,{plr})
end

I don’t believe you need to do game.PlaceID. This would reserve a server just for your hub place which would require you to use the “local isReserved” code that has been posted and quoted. You could try messing around with the game universe and using other placeID’s. The only thing you would have to change is the following:

code = TS:ReserveServer(game.PlaceId) --This is the website's code which would use your hub place
----
code = TS:ReserveServer(other placeID) --Use the placeID for a specific farm place here

I do not know if this would work as it is just a theory and I haven’t tested it. It is worth giving it a shot and maybe you will get it to work that way. Either way, good luck!