I have a social service script that gives you in game currency when you invite someone. The problem, is that if you invite someone twice it gives you twice the currency. How could i make it so you only can invite each player once?
Here is the portion of the script that gives the eggs:
SocialService.GameInvitePromptClosed:Connect(function(player, ids)
local names = {}
for _, id in pairs(ids) do
player.leaderstats.Eggs.Value = player.leaderstats.Eggs.Value + (10) --* player.leaderstats["Egg Multiplier"].Value)
table.insert(names, game:GetService("Players"):GetNameFromUserIdAsync(id))
end
end)
for i,v in pairs(names) do
if game:GetService("Players"):GetNameFromUserIdAsync(id) ~= v then
player.leaderstats.Eggs.Value = player.leaderstats.Eggs.Value + (10) --* player.leaderstats["Egg Multiplier"].Value)
end
end
table.insert(names, game:GetService("Players"):GetNameFromUserIdAsync(id))
The reason your code isn’t working is because you’re creating a new variable every time the GameInvitePromptClosed Event is firing. To fix this, you need to have a variable outside the Event.
The code below will fix that issue.
local names = {}
game:GetService('SocialService').GameInvitePromptClosed:Connect(function(player, ids)
for i, player in next, ids do
table.insert(names,game:GetService("Players"):GetNameFromUserIdAsync(player))
end
end)
Should you be wanting to have it be once permanently, you will have to save the data to a datastore and have it check.