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

Why wont my datastore save strings?

Asked by 8 years ago

I'm trying to make it saves strings and the output said "12:58:44.303 - GetAsync is not a valid member of StringValue". So I'm not sure what to do..

local Items = Instance.new('StringValue', plr)
Items.Value = Items:GetAsync(tostring(plr.UserId)) or ':Pistol:'
Items.Name = 'Items'

1 answer

Log in to vote
1
Answered by
Necrorave 560 Moderation Voter
8 years ago

Regarding datastores, you need to create a datastore object first

You are trying to use the method GetAsync() on something that is not a datastore.

I would recommend you look here for some basic info

Example of creating a datastore:

--Keep in mind, some of these values are placeholders
data = game:GetService("DataStoreService"):GetDataStore(DataStoreName)

Inside of the GetDataStore() method you would usually want to refer to the data store you created previously. Otherwise, it will create a new one.

To Set something to that new datastore you would use SetAsync()

Example:

data:SetAsync("stats", "This is a string")

To Get data attached to those keys, you would use the GetAsync() method.

Example:

result = data:GetAsync("stats") or "Nothing"
print(result)
--This will print whatever value is attached to the key "stats" if there is one.
    --If not, it will print "Nothing" instead.  Hence the `or "Nothing"`

Let me know if you have any other question and be sure to check out the link I provided.

Note: Keep in mind, you will need to check a setting in your game configuration named "Enable access to API services" before using datastores. (You must also edit the game directly, not through a file)

0
Thanks. UltraUnitMode 419 — 8y
0
No problem, good luck with your projects Necrorave 560 — 8y
Ad

Answer this question