Last year I created a singleplayer game that is designed for you to play, get an ending, and then be kicked from the game so you can rejoin and everything in the server will be reset. One year later the game is kind of taking off in popularity and I realize that I can no longer use this old system because of how annoying it is to constantly have to rejoin every time you do something. There’s something like 12 endings in the game currently and many more on the way so I’d like to get this done in a really efficient and polished way so it’ll be a good foundation for more updates.
This all sounds really cool in theory but the issue is- well… it’s a game that I have been working on for an entire year without this feature in mind so it’s not really friendly towards the change ¯_(ツ)_/¯
I wanted to make it so the game was still easily editable so there is a base map with all the scripts disabled that the game copies over off in the distance and this is the map that you play on. After the map is copied all of the scripts are enabled. When the game resets, the map in the distance is deleted and copied over again.
The issue with this is something I found out about disabled scripts.
let’s say in a script you have something like
local example = script.Parent
For some reason even though the script is disabled in the template map it will still run this part of the code and set the example variable to the parent on the original template map instead of waiting until it is enabled and setting the variable on the new map.
I’ve been destroying my brain over a solution to this problem for something like the past 2 months to no success. If any of you guys have a better idea as to how to reset the game then I’m totally down to hear it. Like I said I still want the map to be easily editable and not destroy your computer with lag once you restart the game. If I wasn’t clear enough in any part of this post I can elaborate further.
Thank you for any help,
Ethaniel2004. (this was a really formal closing to a devforum post)
Well… I found a solution that definitely works but it is just painful from a programming standpoint and feel really like a cheep brute force solution.
if you yield the scripts using wait() then they won’t run while disabled
wait()
local example = script.Parent
(with the defect that this would have to be added to most of the scripts in my game)
So this script would work and everything in the game is functional, it just feels SO PAINFUL TO WRITE CODE LIKE THIS IN MY OTHERWISE WELL DONE GAME. Please… if you have any humanity… save me.
I have had this problem in my game and I just teleported them back into the game!
local PlaceID = **InsertId**
game:GetService("TeleportService"):Teleport(PlaceID)
This isn’t the cleanest way because they may be re-teleported into the same server (You could add a teleporter so if they rejoined the same server again it would teleport them again) but it is better to retain players that your strategy previously mentioned. Hope this helps!
I believe that you are able to create an extra place. I would make another place, make people teleport to that place after getting an ending, in there teleporting them back into the main game. Also I enjoyed your game a lot, and even tried to speedrun it once, lol. Anyway, that might work.
alright, I’ve done this system. It’s a testing game i made. You can just make it so upon activation it teleports you to a different game that inside when a player joins, teleports them to the game again. There is a server age calculator inside the game to show if it worked or not. I’ve tested and it worked for me, so lol.
If a script is running when you set it to a Disabled state, it never stops. It is just a quirk of the platform. Have you thought of restructuring the game so it operates on a Round basis.
Simply create a Bool attribute under the Player that changes to true once they have completed the game. Any active scripts should periodically check the value of this script and when true, they should exit all loops and terminate any active connections. Teleport the player back to a lobby, delete and re-generate the map
I already gave this solution to Ethan via discord a few months ago, but I’ll say it here in case people needing help about this same topic end up here,
The reason why I didn’t use this solution is because it makes editing the game take slightly longer since you have to copy everything over from the workspace into storage.