Cannot Find targetPlayer from Roblox's Avatar Context Menu

Hello!

I am trying to make a Roblox version of the game Rock Paper Scissors. To pair two players up, I am using Roblox’s ACM, and adding a “Request Match” button to invite a player to a match. I’m using the wiki source found here to assist me. The problem I am running into is whenever I try to use the targetPlayer value or “target”, I get an error in the studio server simulation with two players saying “target is not a valid member of Players”.

What I am expecting to happen if the script runs normally is the other player sees a GUI with a accept or decline button. If the user accepts, it tells the other user that the invite is excepted and will eventually load a map for the users to play on. The declining function has not been created yet.

Here is the code that I have so far.

game:GetService("StarterGui"):SetCore("SetAvatarContextMenuEnabled", true)

game.StarterGui:SetCore("RemoveAvatarContextMenuOption", Enum.AvatarContextMenuOption.Friend, Enum.AvatarContextMenuOption.Emote)

local Players = game:GetService("Players")

local player = Players.LocalPlayer

local bindableEvent = Instance.new("BindableEvent")

local function onCustomACMAction(targetPlayer)

print("ACM event selected by " ..player.Name.. " on "..targetPlayer.name)

game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

local target = targetPlayer.name

print(target)

game.Players.LocalPlayer.PlayerGui.Sent.Frame.InformationText.Text = "Invite sent to "..targetPlayer.name.." . Waiting for a response from them..."

game.Players.LocalPlayer.PlayerGui.Sent.Frame.Visible = true

game.Players.target.PlayerGui.Invite.Frame.Visible = true

game.Players.target.PlayerGui.Invite.Frame.InformationText.Text = player.Name.. "has challenged you to a game of Rock, Paper, Scissors!"

game.Players.target.PlayerGui.Invite.Frame.OptionYes.MouseButton1Click:Connect(function()

game.Players.target.PlayerGui.Invite.Frame.OptionYes.Visible = false

game.Players.target.PlayerGui.Invite.Frame.OptionNo.Visible = false

game.Players.target.PlayerGui.Invite.Frame.InformationText.Text = "Challenge accepted! Loading game..."

game.Players.LocalPlayer.PlayerGui.Sent.Frame.InformationText.Text = "Challenge accepted! Loading game..."

end)

end

bindableEvent.Event:Connect(onCustomACMAction)

local options = {"Request Match", bindableEvent}

game.StarterGui:SetCore("AddAvatarContextMenuOption", options)

I am not sure if I am just missing something or if this is always going to happen in the test environment. But either way, I’m hoping for a solution soon! Thanks!

If it’s a server script, it wouldn’t work, make sure it is a local script inside of the starter gui

1 Like

I tried what you said. The script is a local script and the same error still occurs even when it is in StarterGui.