Script Part to see gui

Hi, i need help whit my script because i try to do it change visibility of a gui and it say

Workspace.Boton.Boton.ClickDetector.Script:3: attempt to index nil with ‘PlayerGui’


the script is:

script.Parent.MouseClick:Connect(function()

game.Players.LocalPlayer.PlayerGui.Emergencia.Emergenci.ImageTransparency = 0
wait(5)
game.Players.LocalPlayer.PlayerGui.Emergencia.Emergenci.ImageTransparency = 1

end)


Are you doing this inside a ServerScript? LocalPlayer does not work on a ServerScript, you should use a LocalScript rather.

hi, thx for reply
i try what you say and it do nothing
what can i do? thx

OctaLua is right.
Your GUI is on client, the object seem to be in workspace.
On click, get the player, find the GUI component inside the player GUI and set.Visible = false

1 Like

image
image
image
this is

BTW, you speak spanish? I say it due to Emergencia and Boton.
Would be easier for me to explain in spanish xD

BTW. You need to change the Visible in LocalScript, use a remote event from the Object click detector, to send a remote event to the LocalScript inside player’s GUI

si xd, muchas gracias ahjahjha uwu

Necesitas usar un evento remoto lanzado desde el click detector en el script del objeto.

El evento remoto sera leido por un LocalScript dentro del GUI del player. Ahi en ese script es donde haces Visible = false al GUI

osea, coloco un evento remoto en la gui en startergui o como?

Ahorita te escribo los pasos q debes seguir, no tardo mucho

dale, enserio, muchisimas gracias

1 Like

Primero crea un evento remoto dentro de ReplicatedStorage nombralo “hideGui”
Crea una parte en Workspace y crea un Script dentro de la parte, tambien un ClickDetector.
Despues pon un LocalScript dentro del ScreenGui, y pon un Frame tambien

image

image

image

En el script del server osea el del objeto pon esto:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local hideRem = ReplicatedStorage:WaitForChild("hideGui")

local click = script.Parent.ClickDetector

local function disableGUI(player)
	print("disable GUI")
	hideRem:FireClient(player)
end
click.MouseClick:Connect(disableGUI)

Y en el LocalScript dentro del ScreenGui pon:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local hideRem = ReplicatedStorage:WaitForChild("hideGui")

local frame = script.Parent.Frame

local function hide()
	if frame.Visible then
		frame.Visible = false
	else
		frame.Visible = true
	end
end
hideRem.OnClientEvent:Connect(hide)
2 Likes

It says attempt to index nil with 'PlayerGui' because the parent of PlayerGui doesn’t exist, you’re indexing something that doesn’t exist. You should more than likely take it slow.

local Players = game:GetService("Players");
local client = Players.LocalPlayer;
local PlayerGui = client:FindFirstChild("PlayerGui");

if PlayerGui then
    PlayerGui.Emergencia.Emergenci.ImageTransparency = 0;
    wait(5);
    PlayerGui.Emergencia.Emergenci.ImageTransparency = 1;
end

Also in the error it says that it’s a ‘Script’ instead of a ‘LocalScript’, you cannot access LocalPlayer on a general script, which is why the parent of PlayerGui doesn’t exist and is nil; LocalPlayer can’t be accessed via general scripts.

2 Likes