[Solved] PlayerGui is not a valid member of Player "Players.Player1"?

So i want to make a gui appearing for a certain player that touched a part and i am getting a weird output.
Apparently when player1 touches the part player2 client outputs "PlayerGui is not a valid member of Player “Players.Player1"”
local script detecting if player touched the part it’s inside screenGui in starterGui

local brick = workspace.ShopOwner
local RESET_SECONDS = 2
local isTouched = false  

brick.Touched:Connect(function(hit2)
	wait(0.1)
	if hit2 and hit2.Parent:FindFirstChild("Humanoid") then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit2.Parent)
		if not isTouched then 
			isTouched = true 
			player.PlayerGui.Ownershop.Frame.Visible = true
			wait(RESET_SECONDS)
                        isTouched = false
		end
	end
end)

I tried changing the code and putting it as a server script inside the part but i had the same output.

wrap PlayerGui in a WaitForChild() function
player:WaitForChild("PlayerGui").Ownershop.Frame.Visible = true

well, so i am getting an infinite yield here

PlayerGuis are not replicated to other clients. (for example, Player1’s PlayerGui won’t be visible to Player2)

1 Like

yeah i know the thing is i am trying to make a gui visible for player1 and it’s trying to make it visible for player2 and that’s now want to achieve

I think you should move the script to StarterPlayerScripts. And also, if this is a local script, change it into a server script.

Server can’t find player’s scripts. Use remote via replicated.

well i tried that before already and the script seem to not fire the remotes

Actually, why not place the script as a direct child of the object (as a server script).

just tried that it seems to work only once then it’s not working anymore
That’s the local script for closing the gui inside the gui button

function leftClick()
	local plr = game:GetService("Players").LocalPlayer
	local camera = game.Workspace.Camera
	camera.CameraType = Enum.CameraType.Custom
	plr.Character.Humanoid.WalkSpeed += plr.WlkSpd.Value
		script.Parent.Parent.Visible = false	
	wait(0.1)
script.Parent.Parent.Visible = false	
	end
script.Parent.MouseButton1Click:Connect(leftClick)

When you say it only works once but doesn’t work anymore, do you mean like the Gui pops up once but not again? Are you receiving any errors from the output?

yeah no errors or anything just seems to work once then it stops

Could you show your current code in the script to see if there could be anything wrong?

This is inside a part a serverscript

local brick = workspace.ShopOwner
local RESET_SECONDS = 2
local isTouched = false  

brick.Touched:Connect(function(hit2)
	wait(0.1)
	if hit2 and hit2.Parent:FindFirstChild("Humanoid") then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit2.Parent)
		if not isTouched then 
			isTouched = true 
			player:WaitForChild("PlayerGui").Ownershop.Frame.Visible = true
			wait(RESET_SECONDS)
			isTouched = false

		end
	end
end)

and this is inside a button local script

 function leftClick()
	local plr = game:GetService("Players").LocalPlayer
	local camera = game.Workspace.Camera

	
	camera.CameraType = Enum.CameraType.Custom
	plr.Character.Humanoid.WalkSpeed = plr.WlkSpd.Value
		script.Parent.Parent.Visible = false
		
	wait(0.1)
	
script.Parent.Parent.Visible = false
		

	end

script.Parent.MouseButton1Click:Connect(leftClick)

i analysed it few times and i couldnt find anything wrong

Try this if it doesn’t work please tell me the error.
Also I recommend firing a RemoteEvent when the Player touchs the Brick then making the Frame visible inside the Local Script That also might be the issue try this first if it doesn’t work then fire a remote event when the Player touchs the Brick then making the frame visible inside the Local script.

local brick = game.workspace.ShopOwner
local RESET_SECONDS = 2
local isTouched = false  

brick.Touched:Connect(function(hit2)
	wait(0.1)
	if hit2.Parent:FindFirstChild("Humanoid") then
		local player = game:GetService("Players"):GetPlayerFromCharacter(hit2.Parent)
		if isTouched == false then 
			isTouched = true 
			player:FindFirstChild("PlayerGui").Ownershop.Frame.Visible = true
			wait(RESET_SECONDS)
                        isTouched = false
		end
	end
end)

no errors just it works only once then it doesnt

Hmm Can you print after the Reset Seconds?
If it prints then please tell me.

It looks like this is a server script. Since everything from the sever always loads in before stuff from the client you should at a :WaitForChild() for the PlayerGUI since it might not have loaded in yet.

Remote Events then once its fired to sevrer fire player 2’s client
example

server

local remote = script.Parent.RemoteEvent
local part = workspace.ShopOwner

part.Touched:Connect(function(target)
    if target:FindFirstChild("Humanoid") then
       local targetsplayer = game:GetService("Players"):WaitForChild(target.Name)
       remote:FireClient(targetsplayer)
    end
end)

client

local remote = script.Parent.RemoteEvent

remote.OnClientEvent:Connect(function()
    game.Players.LocalPlayer.PlayerGui.GUI_FRAME_WHATEVER.Visible/Enabled = true
end)

it doesnt print anything something might be blocking the code or smth