Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
ArXe66 0
4 years ago
Edited 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

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.

0
we cannot help if you do not explain what you are doing ??? User#5423 17 — 4y
0
if you have fixed it add [solved] to the title User#5423 17 — 4y
0
speaking of the post not the problem ArXe66 0 — 4y

1 answer

Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
4 years ago

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)
Ad

Answer this question