We use cookies on this site to enhance your user experience

Reward Players for Visiting

Reward Players for Visiting

Sep 05 2018, 8:39 PM PST

The code below awards players 50 points every time they join the game by updating a data store.

local pointsDataStore = game:GetService("DataStoreService"):GetDataStore("Points")
 
game.Players.PlayerAdded:Connect(function(player)
	local playerKey = "Player_" .. player.UserId
	-- Give 50 points to players each time they visit
	local success, err = pcall(function()
		pointsDataStore:UpdateAsync(playerKey, function(oldValue)
			local newValue = oldValue or 0
			newValue = newValue + 50
			return newValue
		end)
	end)
end)