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

How do I save a value?

Asked by
SuperFryX 130
9 years ago

I have a String Value in Lighting that I need to save every time its value is changed. But I have no idea how to save anything in Roblox. So basically, how would I save a value, and then load it up again when you come back? I tried reading the Wiki article on Data Store but I had a lot of trouble understanding it.

0
DataStore is complicated, idek but leik gl NotSoNorm 777 — 9y

1 answer

Log in to vote
0
Answered by
funyun 958 Moderation Voter
9 years ago

Some stuff about DataStores: http://wiki.roblox.com/index.php?title=Data_store

Note that you have to enable the DataStore API for your game if you want to try out DataStores in Studio mode. I can't find the link for that because I don't see the check box when I try to configure my place. Maybe someone will post that in the comments.

How to use it in your situation:

dsservice = game:GetService("DataStoreService")
datastore = dsservice:GetDataStore("A string that I have to save in a DataStore") --Here you're either getting a datastore that already exists, or making a new one.

datastore:SetAsync("String", game.Lighting.StringValue.Value) --Saving the StringValue object's Value to the key, "String", in the DataStore that we're using a variable for.

In another script:

dsservice = game:GetService("DataStoreService")
datastore = dsservice:GetDataStore("A string that I have to save in a DataStore")
text = datastore:GetAsync("String") --Gets the value of the key called "String" in the datastore

print(text)
0
Is the string that have to save in data store is the name of the value that saves? Minecrafter09031031 16 — 5y
Ad

Answer this question