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)
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.