local SocialService = game:GetService('SocialService')
function onPlayerAdded(plr)
SocialService:PromptGameInvite(game.Players.LocalPlayer)
end
game.Players.ChildAdded:Connect(onPlayerAdded)
This script is supposed to automatically prompt player invite screen when the player joins. How do I make this work?
one more thing: I did it and it gave me with jumble of code:
Unhandled promise rejection:
CorePackages.AppTempCommon.LuaChat.Utils.getFriendsActiveGamesPlaceIdsFromUsersPresence:13: attempt to index nil with ‘99361251’
CorePackages.Packages._Index.lua-promise-07b6e77b-1bb842c3.lua-promise:82 function new
CorePackages.Packages._Index.lua-promise-07b6e77b-1bb842c3.lua-promise:222 function andThen
CoreGui.RobloxGui.Modules.Settings.Pages.ShareGame.Thunks.ApiFetchUsersFriends:28
CorePackages.Packages._Index.roblox_rodux-a0ab4747-d06ccc8a.rodux.thunkMiddleware:10
CorePackages.Packages._Index.roblox_rodux-a0ab4747-d06ccc8a.rodux.Store:62
CoreGui.RobloxGui.Modules.Settings.Pages.ShareGame.Thunks.FetchUserFriends:19
CorePackages.Packages._Index.roblox_rodux-a0ab4747-d06ccc8a.rodux.thunkMiddleware:10
CorePackages.Packages._Index.roblox_rodux-a0ab4747-d06ccc8a.rodux.Store:62
CorePackages.Packages._Index.roblox_roact-rodux.roact-rodux.connect:149
CoreGui.RobloxGui.Modules.Settings.Pages.ShareGame.Components.ShareGameContainer:55
CoreGui.RobloxGui.Modules.Settings.Pages.ShareGame.Components.ShareGameContainer:30 function init
CorePackages.Packages._Index.roblox_roact.roact.Component:323 function __mount
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:363 function mountVirtualNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:93 function updateChildren
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:119 function updateVirtualNodeWithRenderResult
CorePackages.Packages._Index.roblox_roact.roact.Component:334 function __mount
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:363 function mountVirtualNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:93 function updateChildren
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:119 function updateVirtualNodeWithRenderResult
CorePackages.Packages._Index.roblox_roact.roact.Component:334 function __mount
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:363 function mountVirtualNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:93 function updateChildren
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:119 function updateVirtualNodeWithRenderResult
CorePackages.Packages._Index.roblox_roact.roact.Component:334 function __mount
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:363 function mountVirtualNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:93 function updateChildren
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:111 function updateVirtualNodeWithChildren
CorePackages.Packages._Index.roblox_roact.roact.RobloxRenderer:215 function mountHostNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:359 function mountVirtualNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:93 function updateChildren
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:119 function updateVirtualNodeWithRenderResult
CorePackages.Packages._Index.roblox_roact.roact.Component:334 function __mount
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:363 function mountVirtualNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:93 function updateChildren
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:119 function updateVirtualNodeWithRenderResult
CorePackages.Packages._Index.roblox_roact.roact.Component:334 function __mount
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:363 function mountVirtualNode
CorePackages.Packages._Index.roblox_roact.roact.createReconciler:399 function mountVirtualTree
CoreGui.RobloxGui.Modules.Settings.Pages.ShareGame.InviteToGamePrompt:71 function show
CoreGui.RobloxGui.CoreScripts/InviteToGamePrompt:42
local SocialService = game:GetService("SocialService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function canSendGameInvite(targetPlayer)
local res, canSend = pcall(SocialService.CanSendGameInvite, SocialService, targetPlayer)
return res and canSend
end
local function promptGameInvite(targetPlayer)
local res, canInvite = pcall(SocialService.PromptGameInvite, SocialService, targetPlayer)
return res and canInvite
end
local function openGameInvitePrompt(targetPlayer)
local canInvite = canSendGameInvite(targetPlayer)
if canInvite then
local promptOpened = promptGameInvite(targetPlayer)
return promptOpened
end
return false
end
local function invitePromptClosed(senderPlayer, recipientIds)
-- Handle custom logic for players invited by sender
end
openGameInvitePrompt(player)
SocialService.GameInvitePromptClosed:Connect(invitePromptClosed)