Ad
Log in to vote
0

Datastore attempts to index number with number and fails?

Asked by 21 days 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 21 days ago
Edited 21 days 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 — 21d
0
Leaderstats? Puppynniko 983 — 20d
0
? MrBucketOfficial 39 — 19d
0
like i dont see you setting the value Puppynniko 983 — 18d
Ad
Log in to vote
0
Answered by 19 days ago

Line 17 column 36: Replace the comma to a dot

Answer this question