Why is my Gui not appearing when I click this button?

Hello, recently I’ve had a problem with a Gui not popping up when I click a button, I’ve looked through my script, and tested it many times, and it says it works, but my Gui isn’t showing up. image
This is my script. Every time I press the button in-game, it says the Gui is enabled, but it doesn’t show up, but when I enable it in studio it does show up.

I know why. You have to do it by script.parent.parent ect. Thats because Ui is put into playergui for all players. So when you do startergui it wont replicate to the player. But if you do it in player gui it will.

1 Like

First of all, this is the wrong category. It is supposed to be #help-and-feedback:scripting-support.

Second of all, look at line 2. You’re modifying StarterGui, not PlayerGui
Change the inventory variable to

game.Players.LocalPlayer.PlayerGui.InventoryGui

1 Like

Huh, neither of those worked, and valor I misclicked when I made it code review, sorry about that, but the code works, its just that when the Gui is enabled and the BackgroundTransparency and that stuff is set to 0, the Gui just doesn’t show up.

Both replies to this thread were correct, it might’ve been how you implemented it. You can’t do game.StarterGui.UIObject because that won’t replicate. This was something I ran into a lot (which doesn’t error/warn btw - frustrating for someone new), when I started.

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local InventoryButton = -- add the path here (I can't tell where it is from your code)
local Inventory = PlayerGui:WaitForChild("InventoryGui")

InventoryButton.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
        task.wait(0.2)
        -- path to the frame:Destroy() (don't know where that is either)
        Inventory.Enabled = true
    end
end)

You’d have to make this a LocalScript and put it under StarterPlayer -> StarterPlayerScripts

3 Likes

If the script is located in the Frame, by destroying the frame you will interrupt the script because the script will be destroyed

Try this:

InventoryButton.MouseButton1Click:Connect(function()
wait(0.2)
Inventory.Enabled = true
script.Parent.Frame:Destroy()
end)

Another pro to the way I did it was this wouldn’t happen, but this could work too.

Just make sure not to reference the UIObject under StarterGui >_>

1 Like

Sorry, I hadn’t seen your method

You’re all good. Maybe I should make a do’s and don’ts for new developers (like things that won’t warn/error in your code but you still don’t get the result you were expecting)

1 Like

Wait would the Gui automatically be in PlayerGui or do I have put it there?

Hello! There is an error in line 2 of your script:

local Inventory = game.StarterGui.InventoryGui

You must keep it local. This is where the GUI starts and is for every player but when a local player clicks it, it will NOT work.

Here is a modified code you can replace it with:

local Inventory = game.Players.LocalPlayer.PlayerGui.InventoryGui
local InventoryButton = Inventory.InventoryButton

Make sure it is a local script

StarterGui (roblox.com)

@LMVM2041 no need to repeat it for the fourth time.

Simply implying a detailed reason of why the code was giving them an error and providing a correct solution. :man_shrugging:

Ok idk why but none of those are working for me, can someone get on my game and help me out?

1 Like

ok then lets see this then i guess

Ok I sent it to you IceTheOneAndOnly.

It happens automatically. Every time a player is added, a clone of the UIObjects under StarterGui are put into the Player’s PlayerGui, to then you access it via a LocalScript.

If you post a picture of the way your Gui is set up, I can change the variables in the code I posted to where it would work.

My Gui is in workspace, and this is where the inventory button is. image

I didn’t know where I was supposed to put the Gui.

This is a modified version of the code I posted previously. Try disabling your “InventoryScript” inside of MenuGui and put this code inside of a LocalScript under StarterPlayer -> StarterPlayerScripts

local Player = game:GetService("Players").LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local MenuGui = PlayerGui:WaitForChild("MenuGui")
local InventoryButton = MenuGui:WaitForChild("Frame"):WaitForChild("Inventory")
local Inventory = PlayerGui:WaitForChild("InventoryGui")

InventoryButton.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
        task.wait(0.2)
        InventoryButton.Parent:Destroy() -- Personally, I'd just make it invisible (InventoryButton.Parent.Visible = false)
        Inventory.Enabled = true
    end
end)

image