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