Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a close button function?

Asked by 5 years ago

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!

0
Toggle the visibility of the UI User#6546 35 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
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.

Ad

Answer this question