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

I am having trouble with datastore service. Ideas?

Asked by 5 years ago

I wrapped in a pcall function and get a print statement that says "Error". The code is the same on the roblox developer page. I dont know what to do

local DataStoreService = game:GetService("DataStoreService")
local PointsStore = DataStoreService:GetDataStore("PointsStore")

game.Players.PlayerAdded:Connect(function(player)

    local success,err = pcall(function()
        PointsStore:SetAsync(player.UserId.."-Points",50)
    end)

    if err then
    print("Error")
    end

    wait(1)

    print(PointsStore:GetAsync(player.UserId.."-Points"))
end)

0
is this a server script DinozCreates 1070 — 5y
0
i tried in serverscriptservice and workspace none of them worked jakebball2014 84 — 5y
0
can you print err GoldAngelInDisguise 297 — 5y

1 answer

Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
5 years ago
Edited 5 years ago

Hey,

That script, in theory, works. If you were to play your game online, you'd notice that it would work perfectly fine.

However, in studio, we get an error.

Why? Because you didn't allow Studio Access to API Services. This means that Studio can't use DataStore service. Because of this, as you can see, it printed "Error". (If it weren't for the pcall, you would have received an error before it printing "error").

However, after that, you're doing :

    print(PointsStore:GetAsync(player.UserId.."-Points"))

This will error out because you can't use datastore in studio.

HOW TO FIX THIS:

Go to your game, click "Configure this game", and make sure "Enable Studio Access to API Services:" is checked

You should also always check to see if the user has saved statistics before using the GetAsync() mehtod.

0
thanks jakebball2014 84 — 5y
Ad

Answer this question