Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I am having trouble with datastore service. Ideas?

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)

3 comments

0

is this a server script

0

i tried in serverscriptservice and workspace none of them worked

0

can you print err

1 answer

✓ Accepted answer

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.

1 comment

0

thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.