So, I am trying to make a menu that’s when clicked it opens up a GUI so the player can view it easier, however the code I made isn’t working (I am a builder and my Lua knowledge is very bad haha)
I did insert a ClickDetector into the part, and put the GUI of the menu in “StarterGui”.
The code is:
local button = game.Workspace:WaitForChild("FoodPage")
local clickDetector = button:WaitForChild("ClickDetectorOne")
local gui = script.Parent:WaitForChild("Food")
local function onClicked(player)
gui.Visible = not gui.Visible
end
clickDetector.MouseClick:Connect(onClicked)
I tried watching some videos, but nothing helped.
It does hover over the menu, but when clicked it doesn’t open the GUI.
(The menu is a Model, with 2 pages inside of it - FoodPage and DrinkPage; both got click detectors: the foodpage is called ClickDetectorOne, and the drinkpage is ClickDetectorTwo)
Oh wait so basically you have to set the GUI’s parent to player.PlayerGui
local button = game.Workspace:WaitForChild("FoodPage")
local clickDetector = button:WaitForChild("ClickDetectorOne")
local gui = script.Parent:WaitForChild("Food")
local function onClicked(player)
gui.Visible = not gui.Visible
gui.Parent = player.PlayerGui --sets the gui's parent to the client's player screen
end
clickDetector.MouseClick:Connect(onClicked)
Ok questions, what type of script are you using? (local script or script)
Where is your GUI parented?
This would be a bad idea to do, as from the look of it, my hunch is they arent using a local script, thus if someone were to activate the button, it would well parent it to them, but if someone else clicks the button, the first person will no longer have the UI, but the new player will have it.
That assumes they arent using the use of a local script, so in the cast that they are using a local script this would work.
I am using a regular script, and my GUI is located in StarterGUI as I mentioned. Should I add the line he added and change the script to a local script?
no, all you would need to do is just change the script to a local script and it should work, I dont use ClickDetctors much so it might not work, but only one way to find out!
Here you go!
Current code: (note, both FoodPage and DrinkPage got different codes)
local button = game.Workspace:WaitForChild("FoodPage")
local clickDetector = button:WaitForChild("ClickDetectorOne")
local gui = script.Parent:WaitForChild("Food")
local function onClicked(player)
gui.Visible = not gui.Visible
gui.Parent = player.PlayerGui
end
clickDetector.MouseClick:Connect(onClicked) --added from the reply above, changed nothing