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)
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
Simply implying a detailed reason of why the code was giving them an error and providing a correct solution.
Ok idk why but none of those are working for me, can someone get on my game and help me out?
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.
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)
It’s still not working, could you maybe join the game and help in the game?
Is there any errors in the console? Me joining the game wouldn’t help too much unless you meant in studio
Yeah I meant in Roblox studio.
I don’t work with GUIs much, but you should probably use WaitForChild instead of FindFirstChild. Also, (I’m not really sure about this) try enabling Visible as well
local InventoryButton = script.Parent.Frame.Inventory
local Inventory = script.Parent.Parent.InventoryGui
InventoryButton.MouseButton1Click:Connect(function()
task.wait()
script.Parent.Frame:Destroy()
Inventory.Visible = true
end)
I think this is what you’re trying to achieve.
GUI in the roblox engine is very weird.
Don’t reference a GUI via the game path, just use script.Parent.Parent blah blah because you need to edit the GUI in the user’s PlayerGui, not the Global GUI inside of StarterGui.
I found out how to do it, here is the script