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!
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.