I’ve seen some games start to offer invite rewards for users which can be a multitude of things. I am unsure how they are even checking whether the player is inviting the friend or if the friend even joined after being invited.
from my research there seems to be a method that allows for you to check if a player is friends with another player based on their userid.
using that same method I made a quick script which should do basically what you wanted.
local Players = game:GetService('Players')
function GiveReward(plr)
print(plr.Name)
end
Players.PlayerAdded:Connect(function(newPlayer)
for _,player in pairs(Players:GetPlayers()) do
if not player:IsFriendsWith(newPlayer.UserId) then
continue
end
GiveReward(player)
end
end)
That could work, I’ll see if anyone else has more information but apart for that thanks.
if you didnt like the previous response i found another way which uses a property named FollowUserId.
local Players = game:GetService('Players')
function GiveReward(plr)
print(plr.Name)
end
Players.PlayerAdded:Connect(function(newPlayer:Player)
local MrPopular = newPlayer['FollowUserId']
if not MrPopular then return end
MrPopular = Players:GetPlayerByUserId(MrPopular)
GiveReward(MrPopular)
end)
The other is fine. I can just add a table to the inviters datastore called ‘InvitedFriends’, check if the user hasn’t already claimed their reward from that friend by checking through ID after looping through the table and also checking if the player is friends with the joining player. After that if everything checks out just add the reward.
Which is what I am doing right now.
Like this.
local Players = game:GetService('Players')
local Services = game:GetService('ServerStorage'):WaitForChild('Aero'):WaitForChild('Services')
local DataService = require(Services:WaitForChild('DataService'))
local PlayerService = require(Services:WaitForChild('PlayerService'))
function GiveReward(plr)
end
Players.PlayerAdded:Connect(function(newPlayer)
for _,player in pairs(Players:GetPlayers()) do
if not player:IsFriendsWith(newPlayer.UserId) then
continue -- skips the current play from GetPlayers and moves on
end
if not table.find(DataService[player]['InvitedFriends'], newPlayer.UserId) and player:IsFriendsWith(newPlayer.UserId) then
GiveReward(player)
table.insert(DataService[player]['InvitedFriends'], newPlayer.UserId)
end
end
end)