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

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

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

✓ Accepted answer

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.

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