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

Completely confused with DataStores?

Asked by
funyun 958 Moderation Voter
9 years ago

Months after I've been introduced to data stores, I still don't understand how to use them. I tried this script in Workspace in studio, and the output just tells me that "An error occurred." In the test server, it tells me absolutely nothing. I have no idea what I'm doing wrong here.

datastore = game:GetService("DataStoreService"):GetDataStore("PlayerData by UserID")
http = game:GetService("HttpService")
http.HttpEnabled = true

Default = {
    ["Level"] = 1,
    ["Gold"] = 100,
    ["AdminStatus"] = "User"
}

JCodedDefault = http:JSONEncode(Default)
game.Players.PlayerAdded:connect(

function(player)
    print("Attempting to access "..player.Name.."'s data...")
    wait(3)

    if not datastore:GetAsync(player.userId) then
        print(player.Name.."'s data has not been found. Attempting to write default data...")
        wait(3)

        datastore:SetAsync(player.userId, JCodedDefault)

        if datastore:GetAsync(player.userId) then
            print("Successful.")
        else
            print("Failed.")
        end

    else 
        print("Successful.")
    end
end

)
0
I know it's SetAsync and not PostAsync. I was thinking about HttpService for a moment. funyun 958 — 9y
0
You can make the PostAsync into SetAsync by using the Edit button, so alot of DataStore learners wont be confused Endermanium 25 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

you did postasync, maybe it's setasync?

0
Tried that, still nothing funyun 958 — 9y
Ad

Answer this question