How to delete a GUI clone





I recently took the system of a car dealership, in which after buying a car you need to spawn it. When you press the Spawner button, a clone of buttons with cars is created. I need that when I clicked on the button with the name of the car in the spawner tab, the spawner menu disappeared.

And sorry for my bad english :slight_smile:

1 Like

just make a leave button for it
script a code so that the button can detect if the player clicks it or not
if they click on it, the gui will be destroyed or closed

can you give the script ? i want to edit

edit :

local player = game.Players.LocalPlayer
local OwnedCars = player:WaitForChild("OwnedCars")
local Remotes = game["ReplicatedStorage"]["RemotesForSpawnHere"]
while true do
	wait(1.5)
	for i,v in pairs(OwnedCars:GetChildren()) do
		if v.Value == true and not script.Parent:FindFirstChild(v.Name) then
			local Template = script.Parent.Parent.Template:Clone()
			Template.Parent = script.Parent
			Template.Name = v.Name
			Template.Visible = true
			Template.CarName.Text = v.Name
			
			-- Let say if u have button inside frame ?
			
			local Button = v["ButtonNameHere"]
			Button.MouseButton1Click:Connect(function()
				local VehicleName = v.Name
				-- ok we need to fire remotes 
				Remotes:FireServer(VehicleName)
				
				-- now to close gui , i forgot how to use IsA for Gui
				if script.Parent.Parent.Parent.Name == "Dealership" then
					script.Parent.Parent.Parent.Enabled = false
					
				end
				
				
				
			end)
		
		end

	end

end

this should work i guess…

1 Like

Sup, what script? Thanks for help

did you use my script 100% exact or u change something ? its FireServer and not FiServer

Your script doesnt work. I has changed FiServer

what even FiServer ?? its remotes:FireServer(vehiclename) and not remotes.FiServer . the script assume that the remotes has a child named FiServer thats why it doesnt exist

this one should work , if its doesnt work try to share the output

local player = game.Players.LocalPlayer
local OwnedCars = player:WaitForChild("OwnedCars")
local Remotes = game["ReplicatedStorage"]["DealershipEvents"]["SpawnCar"]
while true do
	wait(1.5)
	for i,v in pairs(OwnedCars:GetChildren()) do
		if v.Value == true and not script.Parent:FindFirstChild(v.Name) then
			local Template = script.Parent.Parent.Template:Clone()
			Template.Parent = script.Parent
			Template.Name = v.Name
			Template.Visible = true
			Template.CarName.Text = v.Name
			
			-- Let say if u have button inside frame ?
			
			local Button = v["ButtonNameHere"]
			Button.MouseButton1Click:Connect(function()
				local VehicleName = v.Name
				-- ok we need to fire remotes 
				Remotes:FireServer(VehicleName)
				
				-- now to close gui , i forgot how to use IsA for Gui
				if script.Parent.Parent.Parent.Name == "Dealership" then
					script.Parent.Parent.Parent.Enabled = false
					
				end
				
				
				
			end)
		
		end

	end

end

and also make sure you put buttontext inside template named ButtonNameHere or if u understand then no need

In this case, you don’t want to delete this GUI; you simply want to make it visually disappear. All you need to do is connect to the Activated event for any given button, and either set the Enabled property of the ScreenGui it’s under to false, or set the topmost level Frame’s Visible property to false.

Assuming that these buttons are automatically made (which they should be!), you can add this function to what your button does:

-- somewhere at the top of your script...
local spawnerFrame = script.Parent -- adjust this to point at the highest level frame in your GUI

-- later on, inside whatever function you use to create the buttons with...
buttonClone.Activated:Connect(function()
    spawnerFrame.Visible = false -- will hide the GUI when clicked, assuming you've correctly pointed spawnerFrame at the correct GUI
)