Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Problem with Gui.Enabled | attempt to index nil with 'PlayerGui' How to fix it?


script.Parent.MouseButton1Click:Connect(function(player)
	local Gui = player.PlayerGui:WaitForChild("Gui")

	Gui.Enabled = false
end)

attempt to index nil with 'PlayerGui'

How to fix this?

2 answers

✓ Accepted answer

Use this instead.

script.Parent.MouseButton1Click:Connect(function()

	local player = game.Players.LocalPlayer

	local Gui = player.PlayerGui:WaitForChild("Gui")

	Gui.Enabled = false
end)

Is this script inside if the gui? If it is, the edit your script to this:

script.Parent.MouseButton1Click:Connect(function()
     script.Parent.Parent.Parent.Enabled = false
end)

Is assumed that you are clicking a text/imageButton inside of a frame inside the gui

This discussion is preserved as it was. New answers, comments, and votes are closed.