local MainFrame = script.Parent local exclusions = { ExcludedFrame1 = function() end,…
- User
local MainFrame = script.Parent
local exclusions = { ExcludedFrame1 = function() end, ExcludedFrame2 = function() end, }
local function onButtonClick(button) local frameName = button.Name
if exclusions[frameName] then -- run the assigned function. else local targetFrame = workspace:FindFirstChild(frameName) if targetFrame and targetFrame:IsA("Frame") then targetFrame.Visible = true print("Frame named '" .. frameName .. "' is now visible.") else warn("Frame named '" .. frameName .. "' not found in Workspace or is not a Frame.") end endend
for _, child in (MainFrame:GetChildren()) do if child:IsA("TextButton") then child.MouseButton1Click:Connect(function() onButtonClick(child) end) end end
tell me what to add in order to accomplish what the comment is asking me for.
- Assistant
To ensure that the assigned function within the
exclusionstable is executed when an excluded frame is clicked, you can modify the code by adding the function call inside theif exclusions[frameName]block. Here's the updated version of your script, with the necessary addition to run the assigned function for excluded frames:local MainFrame = script.Parent local exclusions = { ExcludedFrame1 = function() print("ExcludedFrame1 function executed.") end, ExcludedFrame2 = function() print("ExcludedFrame2 function executed.") end, } local function onButtonClick(button) local frameName = button.Name if exclusions[frameName] then -- Run the assigned function. exclusions[frameName]() else local targetFrame = workspace:FindFirstChild(frameName) if targetFrame and targetFrame:IsA("Frame") then targetFrame.Visible = true print("Frame named '" .. frameName .. "' is now visible.") else warn("Frame named '" .. frameName .. "' not found in Workspace or is not a Frame.") end end end for _, child in MainFrame:GetChildren() do if child:IsA("TextButton") then child.MouseButton1Click:Connect(function() onButtonClick(child) end) end endIn the above code, within the
if exclusions[frameName]condition:- The function corresponding to the
frameNamekey is called usingexclusions[frameName](), ensuring that the specific behavior defined for the excluded frame is executed when the button is clicked.
This fulfills the requirement indicated by your comments. Now, when you click a button named
ExcludedFrame1orExcludedFrame2, the respective function defined in theexclusionstable will be executed. For other buttons, the related frame's visibility will be toggled. - The function corresponding to the