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

Why is this piece of code crashing my studio?

currentgame = script.Parent.Parent.Parent -- all these don't need to be local, unless they are in a function or an if statement or a loop.
menu = script.Parent
play = script.Parent.Play
quit = script.Parent.Quit
upgrades = script.Parent.Upgrades
quitmenu = script.Parent.Parent.Quit
upgradesmenu = script.Parent.Parent.Upgrades
gamemenu = script.Parent.Parent.Game

play.MouseButton1Down:connect(function()--event
    if currentgame.Visible then--no need for == true
        gamemenu.Visible = true
        menu.Visible = false
    end
end)

quit.MouseButton1Down:connect(function()
    if currentgame.Visible then
        quitmenu.Visible = true
		menu.Visible = false
        quitmenu:TweenPosition(UDim2.new(0, 200, 0, 100))
    end
--This part crashes studio vvvvvvvvvvvvvvvvvvvv
	quitmenu.Yes.MouseButton1Down:connect(function()
			menu:TweenPosition(UDim2.new(0, -400, 0, 100))
			quitmenu:TweenPosition(UDim2.new(0, -400, 0, 100))
			quitmenu.Visible = false
			menu.Visible = true
			currentgame.Visible = false
			currentgame.Parent.Parent.Apps.Visible = true
		end)
		
		quitmenu.No.MouseButton1Down:connect(function()
			menu.Visible = true
			wait()
			menu:TweenPosition(UDim2.new(0, 250, 0, 100))
			quitmenu.Visible = false
		end)
end)

Whenever the "quitmenu.Yes" is pressed, it crashes my roblox studio... please explain why this happens, thanks!

1 comment

1

Try putting a wait.

1 answer

Don't put events inside of another event.

put the quitmenu.Yes.MouseButton1Down and quitmenu.No.MouseButton1Down outside of quit.MouseButt1Down.

2 comments

0

You are aware that you can do this, right? It's an event listener.

0

@Pyrondon it's bad practice to put them inside of another one. It will most likely fix the problem too.

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