Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a datastore for boolean values?

Asked by 5 years ago
Edited 5 years ago

I really want to make a game based on collecting keys, trophies, etc; I can't seem to figure out how datastores work, I've tried finding better aid via Youtube, but none of the videos expanded on how to save boolean values, I have an intermediate understanding of scripting, and I need a bit of help.

1 answer

Log in to vote
0
Answered by 5 years ago

To save a boolean value to a datastore (x) you would,

local Data = game:GetService("DataStoreService"):GetDataStore("x")
local Bool = true -- (or false)
local WhatPlayer = some player object

Data:SetAsync("user_"..WhatPlayer.UserId, Bool) -- data key, what to save to data key

-- to retrieve this data:

Data:GetAsync("user_"..WhatPlayer.UserId) -- returns saved data, in this case - true.
0
This is purely to help you understand how it works - it would not be smart to set up a DataStore in this manner. SummerEquinox 643 — 5y
0
I understand now! Thank you so much!!! Bearturnedhuman 48 — 5y
0
Awesome! I'd appreciate it a lot if you would mark the answer as a solution since it has solved your issue. If you have any further questions about DataStores, don't hesitate to post them. SummerEquinox 643 — 5y
0
It wouldn't be recommended to use SetAsync for updating the value. You should be using UpdateAsync User#19524 175 — 5y
Ad

Answer this question