Invite Friends [OPEN SROUCE]

Hello There!

I decided to create this for my friends game and it took around 3 minutes to make as I didn’t know how to use the Social Service. This is really easy to make but I thought I would open source it for new games that don’t have as good scripters.

This is very customizable and is scripted for a user-interface system.

Features:

  • Shows how many friends are online.
  • Live updating friends online count.
  • Pops up invite so you can get friends to join when they click the button.
-----| CONFIGURATION |-----
local IniviteFriendsOnJoin = true -- Replace false with true if you want it to prompt invites to friends when they join the game.

local LocalPlayer = game:GetService("Players").LocalPlayer
local SocialService = game:GetService("SocialService")
local Friends = LocalPlayer:GetFriendsOnline()

repeat wait() until script.Parent.Parent:FindFirstChild("FriendsBackground")
repeat wait() until script.Parent.Parent.FriendsBackground:FindFirstChild("Button")

script.Parent.Parent.FriendsBackground.Button.MouseButton1Click:Connect(function()
	SocialService:PromptGameInvite(LocalPlayer)
	SocialService.GameInvitePromptClosed:Connect(function()
		-- Coming Soon
	end)
end)

if IniviteFriendsOnJoin == true then
	SocialService:PromptGameInvite(LocalPlayer)
	SocialService.GameInvitePromptClosed:Connect(function()
		-- Coming Soon
	end)
end

while wait() do
	local FriendOnline = 0
	
	for Number,Friend in pairs(Friends) do
		FriendOnline = FriendOnline + 1
	end
	
	if FriendOnline == 0 then
		FriendOnline = "NONE"
	end
	
	local FreindsFrame = script.Parent.Parent:FindFirstChild("FreindsFrame")
	local FriendsText = FreindsFrame:FindFirstChild("Text")
	
	if FreindsFrame and FriendsText then
		FriendsText.Text = "FRIENDS ONLINE: "..FriendOnline
	end
end
6 Likes

This is unusable to new scripters if you don’t provide the interface that you used.

3 Likes

I’ll make it a model then I guess.

1 Like
2 Likes

Can you also provide another version of this which will open up the Invite Friends menu when clicking a button?

^ I did with the model above ^

Oh, sorry. I thought the menu popped up when joining, lol.

I can do that too if you want. I have updated the model and script so you can disable or enable join invite.

This is really neat! I was looking for something like this too so thank you! :smiley:

Thank you for your contribution! I just want to say something for the future and to help you with your development:

Using repeat wait() to wait for something is a bad practice, instead, use :WaitForChild:

script.Parent.Parent:WaitForChild("FriendsBackground")

If the waiting is too long, a warning will be printed in the output, but it’s nothing very harmful to the code. And also:

I would like to recommend you this post to read, it explains why you shouldn’t use wait() on specific cases:

Thanks for reading :slight_smile:

You have numerous spelling mistakes in your code. Sometimes you spell friends as ‘freinds’.

Please fix.

1 Like

Unfortunately this is not substantial enough for this category, is incomplete, and uses some poor coding practices. Only submit finished and polished resources.