Why is my code not destroying the gui when I hit play

local gui = script.Parent
local buttons = gui.Buttons

local clickedPlay = false

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)

for i,v in pairs(buttons:GetChildren()) do
if v:IsA(“TextButton”) then
– Do effects.

	v.MouseEnter:Connect(function()
		v:TweenSize(UDim2.new(0.255, 0, 0.079, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.2, true)
	end)

	v.MouseLeave:Connect(function()
		v:TweenSize(UDim2.new(0.231, 0, 0.069, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.2, true)
	end)

	v.MouseButton1Down:Connect(function()
		if v.Name == "Play" and not clickedPlay then
			-- Player clicked play.

			clickedPlay = true

			local t = game.TweenService:Create(gui.Fade, TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {["BackgroundTransparency"] = 0})
			t:Play()

			t.Completed:wait()
			-- then continue.

			gui.Background.Visible = false
			gui.Buttons.Visible = false
			gui.Version.Visible = false

			t = game.TweenService:Create(gui.Fade, TweenInfo.new(1.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {["BackgroundTransparency"] = 1})
			t:Play()

			t.Completed:wait()

			game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, true)
			gui:Destroy()
		elseif v.Name == "About" then
			-- Player clicked about.

			gui.About.Visible = true
		else
			-- Player clicked updates.

			gui.Updates.Visible = true
		end
	end)
end

end

gui.Updates.Back.MouseButton1Down:Connect(function()
gui.Updates.Visible = false
end)

gui.About.Back.MouseButton1Down:Connect(function()
gui.About.Visible = false

end)

Why it not destroying the gui when you hit play,

i don’t think adding events to a i, v loop is essential, why not just create a script in each GUI?

Well its really efficient actually

oh ok but can you explain because i’m kinda confused on how it’s efficient

So basically since your looping through all of the buttons you can attach an event too all of them at once without having to separately make different events

1 Like

Heres a good visualization

for i,v in pairs(buttonsFolder:GetChildren()) do
	v.MouseButton1Click:Connect(function()
		-- do stuff
	end)
end

---- VS

buttonsFolders.button1.MouseButton1Click:Connect(function()
	-- do stuff
end)



buttonsFolders.button2.MouseButton1Click:Connect(function()
	-- do stuff
end)


buttonsFolders.button3.MouseButton1Click:Connect(function()
	-- do stuff
end)


buttonsFolders.button4.MouseButton1Click:Connect(function()
	-- do stuff
end)
1 Like

oh now i understand, thanks for explaining :+1:

1 Like