Help with datastores / tables

I get the following error when running this function:
image

local module = {}
module.AddStatToPlayer = function(datastore, player, amount)
	local store = game:GetService("DataStoreService"):GetDataStore(tostring(datastore) .. "-KronosStore")
	local data = store:GetAsync("data")
	local found = false
	print(#data)
	if data == nil or type(data) ~= "table" or #data == 0 then
		data = {}
		local slot = table.insert(data, {})
		store:SetAsync("data", data)
		table.insert(slot, player.UserId)
		table.insert(slot, amount)
		print("Datastore Malformed, Resetting.")
	else
		for i,v in pairs(data) do
			if v[1] == player.UserId then
				found = true
				if type(v[2]) == "number" then
					v[2] = v[2] + amount
				else
					v[2] = 0
				end
			end
		end
		if found == false then
			local slot = table.insert(data, {})
			table.insert(slot, player.UserId)
			table.insert(slot, amount)
		end
	end

end
return module

How it’s being called:

s = require(game.ServerScriptService.StatHandler) s.AddStatToPlayer("KillStore", game.Players.barfpillow99, 100)
1 Like

What’s the error? Seems like you’re missing some details.

2 Likes

I fixed it, my bad.
If you could now help it would be great ; ).

1 Like