I am a beginner scripter and I am trying to make a shop GUI. I have added an ImageButton with the following script:
local button = script.Parent local shopgui = game.StarterGui.ShopGUI.Frame button.MouseButton1Click:Connect(function() if button.Image == 2596564913 then shopgui.Visible = false end shopgui.Visible = true button.Image = 2596564913 end)
I am wondering why it doesn't work. It is supposed to change the image to an X symbol. The if statement is supposed to check if the image is the X, then to close the Shop GUI.
However, when I playtested, I clicked on the shop icon and it just turned the image blank, and didn't even open the GUI. I've tried adding "else" to it, but it doesn't work either.
All help is appreciated :)
It's because you're getting the StarterGui itself. StarterGui is a container for all GUI'S in ROBLOX. (When a player joins the game all the GUI's and all contents are automatically cloned in StarterGui)
Use PlayerGui when referencing StarterGui
Fixed Scripts:
local player = game.Players.LocalPlayer PlayerGui = player:WaitForChild("PlayerGui").ShopGUI.Frame local button = script.Parent-- change to where your script is located button.MouseButton1Click:Connect(function() if button.Image == "rbxassetid://2596564913" then PlayerGui.Visible = false PlayerGui.Visible = true button.Image = "rbxassetid://2596564913" end end)
OR: (IF you wanted the script to work in StarterPlayerScripts.)
Put the script in StarterPlayer < StarterPlayerScripts.
local player = game.Players.LocalPlayer PlayerGui = player:WaitForChild("PlayerGui").ShopGUI.Frame local button = player.PlayerGui.Button -- change to where your script is located button.MouseButton1Click:Connect(function() if button.Image == "rbxassetid://2596564913" then PlayerGui.Visible = false PlayerGui.Visible = true button.Image = "rbxassetid://2596564913" end end)
@MarkedTomato
said, use "rbxassetid://2596564913"
. This actually gets the id of an image.Let me know if you have more questions.