How would I make an unlockable area like PSX which saves?

Hello Devs! I have been wanting to create a Simulator game which is fully functioning. However, my dreams never came true. I believe that nowadays, Simulator games are the best games on Roblox right now.

But anyways, I have started scripting systems for the Simulator and created a simple :Destroy() script to break the barrier between the area you are in and the area you want to unlock. However, this doesn’t save for the next time you join. I tried using a DataStore to save the barrier’s existence but you can only save strings :slightly_frowning_face:

Does anyone have a solution for this? I Hope you can Help!!

Regards, Flash :blush:
Have a Great day!

1 Like

You can create a number value called Area which gets saved into your data store.

The value increments when you unlock an area and when you rejoin then there should be a local script that deletes the barriers depending on the Area's number value.

Here’s an example:

If the Area value is 2 then destroy the first and second barrier, if its 5 then destroy the first all the way to the 5th barrier.

I’ve personally used this technique everytime i’ve made an area system.

1 Like

Thats not true, you can also save numbers and tables. You can use tables to store multiple values at once.

2 Likes

Ok I understand. So I create another leaderstat called for example Area1 which is a number value. Then use a LocalScript and set the Area1 value to 1 if the barrier is there and if not set Area1 to 2. Would I save this with a regular DataSaving Script?

Can you give me a brief explanation on how to save numbers and tables?

Changing it in a local script will do nothing, instead use remote events.

Storing numbers the same as storing string values, and storing tables is similar as storing string values.

Here is an example of how to store numbers and tables:

local DS = game:GetService("DataStoreService"):GetDataStore("DataStoreHere")
--You can store numbers and fetch it like this:
local key = "key_123"
local number = 123_456_789 --Yes, you can add underscores to numbers like every other programming languages
DS:SetAsync(key,number)
--[[Data store service also has a special function for storing numbers called :IncrementAsync()
Here's how to use it:
]]--
local amountToIncrement = 10
DS:IncrementAsync(key,amountToIncrement) --This will store the number as 123456799
--And here's how to retrieve the number value (we're gonna be using pcalls so that the script doesn't stop when it fails and to check whether it retrieved the data or not)
local data
local success,errormsg = pcall(function()
       data = DS:GetAsync(key)
end)
if success then
      print("Data: "..data)
else
      error("Error: "..errormsg)
end

--Like i said earlier, storing tables is the same as storing string values but its different to retrieve it.
--Here's an example of saving and retrieving a table and then printing the values:
local tableVar = { --tableVar stands for 'table variable' and this type of table is called a 'dictionary'
        a = 1032911, --the value can be pretty much anything as long the syntax and data type is valid, you can either use "," or ";" to seperate the members
        area = 19191,
        something = "a string"
}
key = "key_567"
DS:SetAsync(key,tableVar)
--And here's how you retrieve the value, it will return a table which you can do anything with it like i did in this case:
local success,errormsg = pcall(function()
       data = DS:GetAsync(key)
end)
if success 
      for i,v in pairs(data) do
            print(i..": "..v)
      end
else
      error("Error: "..errormsg)
end

Hope this helps!

1 Like

Thanks for the method on storing tables and numbers. However, I don’t know how to use remote events. Can you give a brief description on that too?

Remote events are used to send messages to the server.

For example, lets just say that you want to increment the Area value by 1, then we’ll create a remote event in replicatedStorage and fire it. Then we’ll create a script to listen for remote events messages. For more info, read this documentation.

(btw i updated the post above to show how to store tables)

1 Like