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

Datastore attempts to index number with number and fails?

Asked by 2 years ago

So when the datastore script tries to get the Cubes value from the Datastore, it gives me an error saying "ServerScriptService.Datastore:9: Attempted to index number with number" which I have no idea on how to fix.

Datastore script:

local datastore = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
    wait()
    local plrid = "id_"..plr.UserId
    local save1 = plr.leaderstats.Cubes

    local GetSaved = datastore:GetAsync(plrid)
    if GetSaved then
        save1.Value = GetSaved[0]
    else
        local NumSave = {save1.Value}
        datastore:GetAsync(plrid,NumSave)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    datastore:SetAsync("id_"..plr.UserId,plr.leaderstats.Cubes.Value)
end)

Leaderstats script:

local Players = game:GetService("Players")

local function leaderboardSetup(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local cubesmade = Instance.new("IntValue")
    cubesmade.Name = "Cubes"
    cubesmade.Value = 0
    cubesmade.Parent = leaderstats
end

Players.PlayerAdded:Connect(leaderboardSetup)

2 answers

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

GetSaved[1] and local GetSaved = datastore:GetAsync("id_"..plrid)

0
it works now, but it won't save. Every time I rejoin the cubes get set back to 0. MrBucketOfficial 39 — 2y
0
Leaderstats? Puppynniko 1059 — 2y
0
? MrBucketOfficial 39 — 2y
0
like i dont see you setting the value Puppynniko 1059 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

Line 17 column 36: Replace the comma to a dot

Answer this question