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

why is screenGUI nil while it's there? [Solved]

LocalScript:

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

plr.PlayerGui:FindFirstChild("InventoryGUI").OpenInventory.Activated:Connect(function()
	if plr.PlayerGui:FindFirstChild("InventoryGUI").Inventory.Visible == false then
		plr.PlayerGui:FindFirstChild("InventoryGUI").Inventory.Visible = true
		else plr.PlayerGui:FindFirstChild("InventoryGUI").Inventory.Visible = false
	end
end)

01:26:17.089 - Players.ArXe66.PlayerScripts.GUIScript:4: attempt to index a nil value

https://gyazo.com/fdf73eb9da959abb3522f3bfe07cc147

i am trying to make a script that opens and closes a GUI window.

3 comments

0

we cannot help if you do not explain what you are doing ???

0

if you have fixed it add [solved] to the title

0

speaking of the post not the problem

1 answer

line 4

plr.PlayerGui:FindFirstChild("InventoryGUI").OpenInventory.Activated:Connect(function()

Activated is for Tool not TextButton.

If you want detect when TextButton is clicked, you will need MouseButton1Click

so it will be like this

local plr = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

plr.PlayerGui:FindFirstChild("InventoryGUI").OpenInventory.MouseButton1Click:Connect(function()
    if plr.PlayerGui:FindFirstChild("InventoryGUI").Inventory.Visible == false then
        plr.PlayerGui:FindFirstChild("InventoryGUI").Inventory.Visible = true
        else plr.PlayerGui:FindFirstChild("InventoryGUI").Inventory.Visible = false
    end
end)

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