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

My data store doesnt save api enabeld?

local Datastore = game:GetService("DataStoreService"):GetDataStore("Sofian-Datastore")
 
game.Players.PlayerAdded:Connect(function(player)

   
    local Key = "Player-ID:" .. player.userId
   
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
   
    local Coins = Instance.new("NumberValue", leaderstats)
    Coins.Name = "Coins"
    Coins.Value = 0
   
    local Rebirths = Instance.new("NumberValue", leaderstats)
    Rebirths.Name = "Rebirths"
    Rebirths.Value = 0

local Power = Instance.new("NumberValue", leaderstats)
    Power.Name = "Power"
    Power.Value = 0
    -- GetAsync
    local GetSave = Datastore:GetAsync(Key)
   
    if GetSave then
        Coins.Value = GetSave[1]
        Rebirths.Value = GetSave[2]
        Power.Value = GetSave[3]
        print("Data loaded for " .. player.Name)
    else
        local Numbers = {Coins.Value, Rebirths.Value}
        Datastore:SetAsync(Key, Numbers)
        print("Data Saved for " .. player.Name)
    end
end)
 
game.Players.PlayerRemoving:Connect(function(player)
   
    local Key = "Player-ID:" .. player.userId
   
    local ValuesToSave = {player.leaderstats.Coins.Value, player.leaderstats.Rebirths.Value}
   
    Datastore:SetAsync(Key, ValuesToSave)
   
    print("Data Saved for " .. player.Name)
end)

this script prints in my studio output i enabeld api services but it still doesnt work

2 comments

0

Are you sure that you enabled in the game's page? If so and it still doesn't work, try and reload studio!

0

I suggest using int values instead of number values

1 answer

✓ Accepted answer

This may be because you're using player.userId instead of player.UserId. I'm not 100% sure though.

To fix this, just capitalise the "user" at lines 6 and 39.

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