I am trying to make a button fire a remote to the server when pressed; however, the MouseButton1Down event does not seem to be working. I have adjusted the ZIndex of the button (to make it clickable) and attempted to print inside of the event, but nothing is printing.
The loop is working, but it is not connecting the function to the event:
for _, frame in ipairs(script:GetDescendants()) do
if frame.Name == 'Locked' and frame:IsA('Frame') then
updateLockedFrame(frame)
frame.Main.Research.Button.MouseButton1Down:Connect(function()
game:GetService('ReplicatedStorage').Events.Research:FireServer(frame.Type.Value)
end)
frame.Main.ResearchMAX.Button.MouseButton1Down:Connect(function()
game:GetService('ReplicatedStorage').Events.Research:FireServer(frame.Type.Value, true)
end)
end
end
Ensure you are calling that on an object that is higher up then any other elements just to be safe, and that you’re doing it on the frame or button and not the folder.
I have had issues with hit detection, if you have a decorated button just make an element that is invisible and/or higher up on the z index.
You may have to wait for the script’s descendants to load before you loop through them. I think when your script runs, the script’s descendants haven’t loaded in yet and the loop therefore isn’t looping through any descendants
You can make separate variables for each frame, for example
local Frame1 = script:WaitForChild("Frame1")
local Frame2 = script:WaitForChild("Frame2")
Another way you can do this is to have a table with the name of all the frames you want to loop through, for example
local FRAMES_TO_LOOP = {
"Frame1";
"Frame2";
}
for _, frameName in pairs(FRAMES_TO_LOOP) do
local Frame = script:WaitForChild(frameName)
--execute code here
end
However, I noticed you want to loop through all descendants of a script that is a frame. In that case, one possible solution is to use a nested table that mimics the organization of these frames in the explorer, like so:
To keep simplicity, I ended up rewriting the system to make the functions connect using :ChildAdded() after they are cloned to a specific frame and now works.
I appreciate everyone who has helped in the thread