Hi guys. I recently came up with a really good and unique idea (with a lil bit of inspiration) for a horror game. Sadly it will take me like a year, cuz the main mechanic of this game is hard to make. And the game’s main mechanic is:
DataStores.
Confusing, ain’t it? So by that i mean when i get kicked from the game (by SCRIPT, not by error/disconnection) after rejoining something different happens. The problem is that i have n o idea on how to use them properly. That’s why i need help on it. Anyone knows how i can do that?
Roblox has a great Tutorial on how to save Data!, but I can quickly summarize it for you.
First, on a ServerScript, we need to get the Data Store (I named it PlayerProgress, you can change it if you want):
local DataStoreService = game:GetService("DataStoreService")
local progressStore = DataStoreService:GetDataStore("PlayerProgress")
And when we’re about to kick the Player, we set it like this:
local userid = playerToKick.UserId -- Player Data is set with the User Id
local success, message = pcall(function()
progressStore:SetAsync(userid, 1) -- 1 is the value it is going to set the store
end)
if not success then
-- Do things here if setting progress went wrong.
end
playerToKick:Kick("optional kick message here!")
So, maybe inside a Players.PlayerAdded Event to act as quickly as possible, when we want to get the Player’s Progress, we can use this:
local userid = player.UserId
local success, progress = pcall(function()
return progessStore:GetAsync(userid) -- returns the value to progress
end)
if not success then
-- do things here, if nothing could get loaded from the store, maybe because a
-- Player joined for the first time.
end
This question is almost definitely fruitless, but in what manner is your key game feature datastores? I feel intrigued, considering a section of your game is most likely being occluded.
Hm. I’m struggling to understand, could you perhaps briefly explain your game? Is it as if you would like to save the game state (also describing what properties of said state you want to save would help) and then reload it when the player rejoins?
Well i want to do it if i kick the player with the script, it would save it as the player has beaten level 1 and now is going to the lvl 2 after rejoining, and load the new sections of the game. It would work like “Im Scared” if you want to check it.
Will or do you have a pre-existing system to load in the levels based on a simple input? i.e you tell the system that the player is on level 5, then you can simply load it in. If you do, then all you need is a simple datastore that you can find above from @TheHobber1712 or on the Roblox API documentation.
Much love! I’ll be present for questions if needed, good luck.