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

Can someone tell me what I am doing wrong when changing a value in this datastore?

So I have these lines of code:

local function IncrementMoney(player)
	while true do
		wait(4)
		local PlayerStats = DataStoreService:GetDataStore("PlayerStatsTest"):GetAsync(player.UserId)
		print(PlayerStats)
		PlayerStats:IncrementAsync("Money", 10)		
	end
end

When it hits print(PlayerStats) it prints out this:

  {"DeckCount":1,"Wins":0,"Money":100,"Losses":0,"Reputation":0,"GamesPlayed":0,"LifePointsLost":0,"LifePointsDealt":0}

Yet when it goes to Increment "Money" it gives me this error: 15:48:07.950 - ServerScriptService.LoadPlayerData:181: attempt to call method 'IncrementAsync' (a nil value)

2 comments

0

I realize that I'm getting Datastore over and over again so I probably can move that outside of the while loop.

0

When I try and print Money from the datastore it also says it's a nil value so I don't know why it would do that.

1 answer

✓ Accepted answer

IncrementAsync is a function of GlobalDataStore, meaning it can only be used on a DataStore userdata. To solve your issue, remove :GetAsync() from your variable declaration. See this answer to further understand why this is contradictory towards applying IncrementAsync, or read up on IncrementAsync

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