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

"Attempt to index nil with enabled?"

local Inventory = game.Players.LocalPlayer.PlayerGui:findFirstChild("Inventory")
local Shop = game.Players.LocalPlayer.PlayerGui:findFirstChild("Shop")

function openShop()
	Inventory.Enabled = false
	Shop.Enabled = true
end

script.Parent.Frame.Shop.MouseButton1Click:connect(openShop)

Inventory and Shop are both ScreenGuis

For some reason there's an error on the "Inventory.Enabled = false" and I'm not sure why.

2 comments

0

try enabling visible on a frame inside inventory

0

Tried it but unfortunately it didn't work

2 answers

The first thing I see is to try to change findFirstChild to FindFirstChild

I find that if you mess up a capitalization it can error the script completely so try this and tell me your result

Here is the updated script.

local Inventory = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Inventory")
	local Shop = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Shop")
	 
	function openShop()
	    Inventory.Enabled = false
	    Shop.Enabled = true
	end
	 
	script.Parent.Frame.Shop.MouseButton1Click:connect(openShop)

2 comments

0

I tried this too but I still am getting the same error. Thank you for your help though.

0

I seriously don't know why, make sure nothing else is named the same.

Found the solution. It was because the localscript was inside a screengui instead of directly under "StarterGui".

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