CanSendGameInvite not a valid member of Social Service

My code:

local SocialService = game:GetService("SocialService")
local player = game.Players.LocalPlayer
local P = player:WaitForChild'PlayerGui'
local button = P.ScreenGui.Buttons.Invite
 
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)
	if canSendGameInvite(targetPlayer)then
		return promptGameInvite(targetPlayer)
	end
	return false
end
 
local function onActivated()
	openGameInvitePrompt(player)
end
 
button.Activated:Connect(onActivated) 
button.Visible = canSendGameInvite(player)
button.Activated:Connect(onActivated)

Error : CanSendGameInvite not a valid member of Social Service.
This code was taken from roblox developer page. I’m making a Invite system in my game.

Where have you put this script?

The writer of that code made typo when writing the function name, because it’s called CanSendGameInviteAsync and not CanSendGameInvite. Just correct the name and it should work.

1 Like

Oh alright!

local script inside startergui

yeah i think jelliedbanana is right. the guy on the hub must’ve made a typo