How do I reward player if they're in the group, only once?

I know it has to do with Player:IsInGroup() and adding coins to their leaderstats, but how do I keep track of whether or not they already got the reward? Here’s my code so far:

local group = 10829003

function PlayerAdded(Player)
	if Player:IsInGroup(group) then
		print(Player.Name..' is in the group! Rewarding...')
		local LS = Player:WaitForChild('leaderstats')
		local Coins = LS:WaitForChild('Coins')
		Coins.Value += 1000


Also, I heard liking the game rewards aren’t allowed, but is this allowed?

You could use a datastore and bool so that if the bool is true then you reward them, else do nothing.

1 Like

You need to assure that the player’s data contains a boolean or anything that will check whether the player has been in the group and rewarded before. Whenever you load the next time, it is always true and then you should not award the player then. When they are rewarded, toggle and save the boolean.

1 Like

An example is shown below.

local DSS = game:GetService("DataStoreService"):GetDataStore("data1");
local groupid = 11111 -- replace this with your group id

if player:IsInGroup(groupid) then
local data = DSS:GetAsync(player.UserId) or false;
if not data then
DSS:SetAsync(player.UserId, "rewarded");
-- code for the reward
else return;
1 Like