Player Invite System Trouble

I have a bindable function that returns a player’s UserID. I am trying to make these frames and buttons only become visible on the client of the player with the returned userID. However, I can return my own userID and the frame becomes visible on my client, but when I try to return another player’s userid, it does not become visible on their client and I get the error "PlayerGui is not a valid member of Player “Players.(player username)”. Furthermore, I tried other solutions and I did not get errors, but the same thing happened. I have read other similar problems on the forum, but I am not really sure how to fix this. Do I need to change this local script to a server script? How should I modify my code?

--LocalScript
local Players = game:GetService("Players")
local inviteFunction = game.ReplicatedStorage:WaitForChild("InviteFunction")

inviteFunction.OnInvoke = function(playerID)
	local player = Players:GetPlayerByUserId(playerID)
	if player then
		local playerGui = player.PlayerGui
		if playerGui then
			local targetFrame = playerGui.ScreenGui.JoinFrame
			local joinButton = targetFrame.JoinButton
			local ignoreButton = targetFrame.IgnoreButton
			if targetFrame then
				targetFrame.Visible = true
				ignoreButton.Activated:Connect(function()
					targetFrame.Visible = false
				end)
				joinButton.Activated:Connect(function()
					targetFrame.Visible = false
				end)
			end
		end
	end
end
  1. You cannot access PlayerGui or PlayerScripts as a client of another client.
  2. Even if you can, changing them locally would only replicate for you, not to them.

Send a RemoteEvent signal to the server, then let the server send another signal back to the receiving player to update their own gui.

2 Likes