Need help with Click part/model to show GUI

Right now im trying to create a script when you click on a part/model it will make the GUI visible

BUT im trying to make it so 3 parts/models scattered around the game will show the same GUI

The issue is that only 1 Part works while the other 2 dont make the GUI visible

Ive tried looking for solutions and making a new script in server script to see if it would work. But nothing

My process so far:

Ive created a ScreenGui with a frame and named it and i have a part/model with a click detector.

When i press only one of the models it shows the GUI ive made while the others dont show anything.

heres the code its simple enough to locate the part and to make GUI visible:
(ALL THE PARTS ARE NAMED THE SAME)

local Button = game.Workspace.MenuBlock 
local Click = Button.ClickDetector
local Gui = script.Parent.MenuFrame

Click.MouseClick:Connect(function(player)
	Gui.Visible = not Gui.Visible
end)
2 Likes

you need to name the parts differently and create seperate mouse click events for each part, or move all the parts into a folder and iterate over the folder, setting up the mouse click listener for each child
example:

local buttonFolder = workspace.Buttons
for _, button in pairs(buttonFolder:GetChildren()) do 
    button.ClickDetector.MouseClick:Connect(function(player)
	    Gui.Visible = not Gui.Visible
    end)
end
3 Likes

For this code would i need to rename them or just keep them in a folder?

2 Likes

if you use the folder method they can have thesame name

2 Likes

So if i use this code you provided i just change buttons to the folder name

2 Likes

you can leave the names just put the buttons in a folder

2 Likes

What do i rename so it can locate them? cuz the script is in the ScreenGUI

2 Likes

where is the screengui?

(30cdjhars)

2 Likes

its placed in StarterGUI… also whats the brackets u typed

2 Likes

yes you can change the workspace.Buttons in that code to wherever your buttons folder is. the brackets was just to reach the 30 min characters

2 Likes

Was i supposed to move the GUI into the folder?

2 Likes

you can leave the gui in startergui

2 Likes

Thats the problem how does it know what its called then? it doesnt define it in the script

2 Likes

you can define hwere the folder is in the script like this

local folder = workspace.ExampleFolder
1 Like

played around with the code and it finally worked

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.