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

Datastores not working in Roblox studio? Is it my code or just the api

So I'm trying to create a datastore with leaderstats and the leaderstats bit is working but I can't seem to get the data store to work. Here is my code

print("ji")
local DSS =  game:GetService("DataStoreService")
local mydatastore = DSS:GetDataStore("Madata")
print("ye")
    print(player)

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    local Cash = Instance.new("IntValue")
    Cash.Name = "Cash"
    Cash.Parent = leaderstats
local UserId = "Player_"..player.UserId
local data 
local success,errormessage = pcall(function()
  data  = mydatastore:GetAsync(UserId)

end)
if success then 
 Cash.Value = data     
end
end)



game.Players.PlayerRemoving:Connect(function(player)
    local playerUserId = "player_"..player.UserId
    local data = player.leaderstats.Cash.Value 
local success,errormessage = pcall(function()
                    mydatastore:SetAsync(playerUserId,data)
 
        end)
        if success then
            print("The data saved")
        else
         print("Therewasanerror")
                    warn(errormessage)

end
end)

game.Workspace.Script.Part.ClickDetector.MouseClick:Connect(function()
	l
end)

Here are the errors I've got:

15:59:32.614 - Untitled Game auto-recovery file was created
  ji
  ye
  nil
15:59:54.816 - Disconnect from 127.0.0.1|63779
  Therewasanerror
  15:59:54.835 - 502: API Services rejected request with error. HTTP 403 (Forbidden)
16:01:29.451 - ScriptNavigationHandler : No script currently available. (x2)
16:03:45.467 - Untitled Game auto-recovery file was created

Thank you for your help!

2 comments

0

Are API Services on? Are you testing in studio or in the Roblox Player?

0

Studio

1 answer

You need to enable it from the game settings.

in Roblox Studio > Home > Game Settings > Options > Enable Studio Access to API Services

1 comment

0

I have but it still doesn't work

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