You can do
01 | local player = game.Players.LocalPlayer |
02 | local Button = (Button Here) |
03 | local Service = game:GetService( "SocialService" ) |
06 | local success, err = pcall ( function () |
08 | Service:CanSendGameInviteAsync(player) |
13 | if success = = true then |
14 | Service:PromptGameInvite(player) |
19 | Button.MouseButton 1 Click:Connect(OnPressed) |
20 | Button.TouchTap:Connect(OnPresed) |
The code above is the code that will work, you can also just look at the thing below to help you out that's the comments.
local player is getting the player, and button is your button that you should use in this context. Service is the Social Service!
you can then function that into a pcall, and return the Server:CanSendGameInviteAsync(player), player can be localized above and can just do local players = game.Players.LocalPlayers
After that you can Prompt the game invite by simply doing Service:PromptGameInvite(player) which prompts it to that one player bringing the player invite thing up. Then whenever the button is pressed (the UI Button, you can just do Button.MouseButton1Click:Connect(OnPressed) and (Button.TouchTap:Connect(OnPressed)
Remember, that you can only do that if you function the OnPressed, aka
function OnPressed()
-- Code Here / Pcall, and CanSendGameInviteAsync()
end)
if the result == true then you can prompt the game invite, result is equal to anything you call in the pcall, (aka, success, worked, passed, connected etc) and then you can add an else statement and print(err) or the error message you got.
end)