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

ServerScriptService.leaderstats:23: attempt to call a table value. Wheres the error?

Asked by 3 years ago

When I was making my saved leaderboard stats, I got this error. Does anyone know how to fix it? The error is supposedly in line 23 by the way.

Script:

local datastore = game:GetService("DataStoreService"):GetDataStore("Savedata")

game.Players.PlayerAdded:Connect(function(player)


    local stats = Instance.new("Folder", player)
    stats.Name = "leaderstats"

    local wins = Instance.new("IntValue")
    wins.Name = "Wins"
    wins.Parent = stats

    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Parent = stats

    local key = "player"..player.userId

    local SavedValues = datastore:GetAsync(key)

    if SavedValues then

        wins.Value = SavedValues(1)
        coins.Value = SavedValues(2)

    else

        local ValuesToSave = {wins.Value, coins.Value}
        datastore:SetAsync(key, ValuesToSave)

    end

end)

1 answer

Log in to vote
0
Answered by 3 years ago

Howdy!

To index a table, you use brackets - not parenthesis. Replace lines 23 and 24 with what I got below and it should work.

        wins.Value = SavedValues[1]
        coins.Value = SavedValues[2]

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

Ad

Answer this question