We use cookies on this site to enhance your user experience

Increment Data Store

Increment Data Store

Sep 05 2018, 7:10 PM PST

This example uses a data store to increase the value of a key, reflecting how many times a player has visited your game. Because GlobalDataStore/IncrementAsync|IncrementAsync() returns the incremented value, you can reward the player based on how many times they’ve visited.

local visitsDataStore = game:GetService("DataStoreService"):GetDataStore("PlayerVisits")

	local playerKey = "Player_" .. player.UserId

	local visits
	local success, err = pcall(function()
		visits = visitsDataStore:IncrementAsync(playerKey, 1)

	if success and visits == 10 then
		-- Reward player for visiting ten times