Hey, I'm having difficulties with getting DataStore2 to work with my game. At the end of the game/loop, the game is supposed to get all the winners and increment their score by 1. For now, I just made it so all players get their score incremented by 1. I think my problem is that I am failing to understand how to mass increment, or increment several scores at the same time.

This is how I have it set up

local DataStore2 = require(1936396537)
local defaultValue = 0

game.Players.PlayerAdded:Connect(function(plr)
	local winsDataStore = DataStore2("Wins",plr)
	
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"

	local wins = Instance.new("IntValue", leaderstats)
	wins.Name = "Wins"
	
	
	local function winsUpdate(updatedValue)
		wins.Value = winsDataStore:Get(updatedValue)

	end
	
	winsUpdate(defaultValue)
	winsDataStore:OnUpdate(winsUpdate)
	
end)



function AddWins(player)
	local winsDataStore = DataStore2("Wins",player)
	for key,value in pairs(players) do
		winsDataStore:Increment(1,defaultValue)
	end
end

this is how I am calling it in the while loop

AddWins()

The error appears to come up in the actual Module itself, though I haven't messed with the Module at all. This is the error:

14:58:10.418 - Model.MainModule:566: DataStore2() API call expected {string dataStoreName, Instance player}, got {string, nil}

and this is the line it is on

assert(typeof(dataStoreName) == "string" and typeof(player) == "Instance", ("DataStore2() API call expected {string dataStoreName, Instance player}, got {%s, %s}"):format(typeof(dataStoreName), typeof(player)))

If you can tell me how I should do this, it would be greatly appreciated.

5 comments

0

What script doesnt work?

0

It's just not incrementing. I assume it is the first one, the error appears in the module script, but it works when I put the datastore increment function under a clickdetector, it just doesn't when I want to increment everyone's scores. Partly, because I don't know how to increment everyone's scores at the same time. I posted all the data because it might make it easier to see what's going, idk

0

you can use a for loop to loop through the children And when your trying to get all the players use the :GetPlayers() function.

0

can I use a for loop to loop through players in a table? Because I'm going to have to learn that in order to access the winners in a group, and increment all their scores

0

in the AddWins() are you actually putting the player instance in the function?