Is there a way to detect if you invited friends and if so could I make it so when you invite a friend you get money for it?
Yeah, there is a way to do it.
How would I go about doing that.
You can use these apis:
PlayerAdded, PlayerIsFriendWith,FollowUserId
Example:
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do -- gets all the players
if v ~= plr then -- checks if its not the plr who joined
if v:IsFriendsWith(plr.UserId) then -- check if plrs are friend
v.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 10 -- gives them 10 cash
end
end
end
end)
how to give them 10 cash if they invited one, but they didn’t joined?
Well that will be useless because, everyone can invite ton of plrs and even there alts to get tons of money.
Use the SocialService
What im trying to do is, is when you click invite then it gives you the cash
i need that too but idk how to make it
This is the social service @official_rbxreece @ByGoalZ
Also, there a way to know when a player join with a Social Invite invitation but i don’t know how exactly
Heres the code. Just stick this in a local script inside a textbutton
local button = script.Parent
local SocialService = game:GetService(“SocialService”)
local player = game.Players.LocalPlayer
function onButtonPressed()
local Success, result = pcall(
function()
return SocialService:CanSendGameInviteAsync(player)
end
)
if result == true then
SocialService:PromptGameInvite(player)
end
end
button.MouseButton1Click:Connect(onButtonPressed)
button.TouchTap:Connect(onButtonPressed)
that didn’t send the way I wanted it to
Well, i don’t think its possible. But why you need this way tho? like i can just get ton of money by inviting my alt over and over again.
i suggest you not to do this.
see this post:
Yeah your right. But that script you sent is that saying once my friend joins the server, then it gives me my 10 Cash?
Yes it does, you can try. by inviting any of your friends.
You can also detect if the same player is rejoing the server. Then it wont give them cash
so here’s the code.
STEPS:
- Create a server script in ServerScriptService ( you can add it in your leaderboard too )
- Type the following code.
Code
game.Players.PlayerAdded:Connect(function(plr)
local leaderboard = Instance.new("Folder")
leaderboard.Name = "leaderboard"
leaderboard.Parent = plr
local friends = Instance.new("Folder") -- creates a folder named friends
friends.Name = "InvitedFriends"
friends.Parent = plr
local cash = Instance.new("NumberValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderboard
end)
game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(game.Players:GetPlayers()) do -- gets all the players
if v ~= plr then -- checks if its not the plr who joined
if v:IsFriendsWith(plr.UserId) then -- check if plrs are friend
if v.InvitedFriends:FindFirstChild(plr.UserId) then -- Checks if the plr is already invited once
return -- if yes then does nothing
else -- if no then gives them cash and add a value
local value = Instance.new("NumberValue")
value.Name = plr.UserId
value.Parent = v.InvitedFriends
v.leaderstats.Cash.Value = v.leaderstats.Cash.Value + 10 -- gives them 10 cash
end
end
end
end
end)