Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

i made this invite friends button but idk whats wrong in the code?

this is the code it is in local script and the local script is in a button

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
	)
	end
	
	if result == true then
		SocialService:PromptGameInvite(player)
		end
end

button.MouseButton1Click:Connect(onButtonPressed())
button.TouchTap:Connect(onButtonPressed())

1 comment

0

Provide the error next time so others can be better equipped to assist you.

1 answer

✓ Accepted answer

You’re attempting to call a function in an argument feed; the :Connect() method is expecting a function callback, you instead ran the function in the parentheses where this callback is specified. This is a common mistake, simply remove the trailing parentheses at the end of onButtonPressed:

--// Your code was a bit unorganized, so I cleaned it and applied some efficiency changes.
local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local Button = script.Parent

function onButtonPressed()
    local Handler = SocialService.CanSendGameInviteAsync
    local Success, Result = pcall(Handler, SocialService, Player)
    if (Result) then
        SocialService:PromptGameInvite(Player)
    end
end

Button.MouseButton1Click:Connect(onButtonPressed)
Button.TouchTap:Connect(onButtonPressed)

If this helps, don’t forget to accept this answer!

1 comment

0

Thanks alot

This discussion is preserved as it was. New answers, comments, and votes are closed.