Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

local MainFrame = script.Parent local exclusions = { ExcludedFrame1 = function() end,…

  1. 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
    end
    

    end

    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.

  2. Assistant

    To ensure that the assigned function within the exclusions table is executed when an excluded frame is clicked, you can modify the code by adding the function call inside the if 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
    end
    

    In the above code, within the if exclusions[frameName] condition:

    • The function corresponding to the frameName key is called using exclusions[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 ExcludedFrame1 or ExcludedFrame2, the respective function defined in the exclusions table will be executed. For other buttons, the related frame's visibility will be toggled.