Hi everyone, I am trying to come up with a script that rewards you with 5 in game points if you invite a friend (5 points per friend invited), and the script I made hasn’t been working so far. How can I fix it?
Here is what I did so far:
local button = script.Parent
local SocialService = game:GetService("SocialService")
local player = game.Players.LocalPlayer
button.MouseButton1Click:Connect(function()
script.Parent:TweenSize(UDim2.new(0.641, 0,0.039, 0), "In", "Linear", 0.05)
wait(0.051)
SocialService:PromptGameInvite(player)
script.Parent:TweenSize(UDim2.new(0.691, 0,0.089, 0), "In", "Linear", 0.05)
end)
SocialService.GameInvitePromptClosed:Connect(function(player, ids)
local PointsPerInvite = 5
local PointsMade = #ids * PointsPerInvite
player.leaderstats.Points.Value = player.leaderstats.Points.Value + PointsMade
end)
As far as I am aware, no function / event exists to allow you to check how many players the player has invited. This can be verified through checking the Social Service Documentation.
If you are wanting to reward people for inviting, then you could simply do it based on if a player joins the game and a friend is within that server.
Why you may not want this as a feature anyway:
Essentially, players could then farm points by inviting their 200 member friend list and then server hopping. This could then make your game trivial and easy to become “the best” at.
Your logic is sound, although the problem here is that you’re running things in a localscript that are meant for a script on the server.
You’ll need to add a remote event to ReplicatedStorage and then call it to activate a function on the server, which will in turn prompt the game invite on the player. The .GameInvitePromptClosed event would then also need to go into that server script.
If you ever played some mobile or multilplayer-based games, you’d see that what they so to replicate this invite friends system is: when a player joins the game for the first time ever (you can check that by datastoring a boolean saying wether he played before or not), they get prompted a UI saying wether they were told about the game by someone else, if so they write the someone’s else name. Assuming each player’s points are saved using a key that is composed of that player’s UserId (and additional stuff like userid.."-points"), you can use Players:GetUserIdFromNameAsync() to get the player’s UserId, and like that add 5 points to how many points he has, even if he isn’t in the same server or currently offline.