Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you make a close button function?

Hi helpers, This question has to do with my previous one. I made a UI with a close button, and a function for the close button but I do not know how to script the close button without the variable in the Clicked function.

local C1 = script.Parent.Parent.Chassis.ClickDetector
local C2 = script.Parent.Parent.LTrack.ClickDetector
local C3 = script.Parent.Parent.RTrack.ClickDetector
local C4 = script.Parent.Parent.Turret.ClickDetector


function Clicked(playerWhoClicked)
	local UI = game.ServerStorage.UnitUI:clone()
	UI.Parent = playerWhoClicked.PlayerGui
end
function Close()
	local XButton = UI.Background.Close
	UI:Destroy()
end
C1.MouseClick:connect(Clicked)
XButton.MouseButton1Down:connect(Close)

Ignore the C2, C3, and C4.

A response would be appreciated!

1 comment

0

Toggle the visibility of the UI

1 answer

local C1 = script.Parent.Parent.Chassis.ClickDetector
local C2 = script.Parent.Parent.LTrack.ClickDetector
local C3 = script.Parent.Parent.RTrack.ClickDetector
local C4 = script.Parent.Parent.Turret.ClickDetector

 local XButton = UI.Background.Close

function Clicked(playerWhoClicked)
    local UI = game.ServerStorage.UnitUI:clone()
    UI.Parent = playerWhoClicked.PlayerGui
end
function Close()
    UI:Destroy()
end
C1.MouseClick:Connect(Clicked)
XButton.MouseButton1Down:Connect(Close)

All you have to do is move the XButton variable out of the function, because you made it a "local function," the variable is local to the variable, meaning no code outside of the variable can access it.

This discussion is preserved as it was. New answers, comments, and votes are closed.