So I am making a computer thing. And it has a background that changes a decal every few seconds.
But whenever I have clicked the GUI Button clicked I want it to break. But there is no way that I know how to because the TicketButton.ClickDetector.MouseClick:Connect(function()
is outside of the while true do
loop.
Here is my code.
-- // Varibles local ComputerScreen = game.Workspace.Computer.ComputerScreen local Decal = game.Workspace.Computer.ComputerScreen.Decal local TicketButton = game.Workspace.ComputerScreen.SurfaceGui.TicketButton --------------------------------------------------------------------------------- -- // Script while true do game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4652375883" wait(0.5) game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4648289865" wait(0.5) game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4652374880" end TicketButton.ClickDetector.MouseClick:Connect(function() game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=0" TicketButton.BackgroundTransparency = 0 TicketButton.TextTransparency = 0 end)
But whenever I do,
TicketButton.ClickDetector.MouseClick:Connect(function() game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=0" TicketButton.BackgroundTransparency = 0 TicketButton.TextTransparency = 0 ``break`` end)
It errors with a statement, "break statement must be inside a loop".
Is there any way to help me or fix this issue?
Sorry if I make no sense and or this is not even possible, I am a bit new to scripting. Ha! :D
Simply create a boolean variable such as running
, and only run the loop while running is true. Then, you can easily stop the loop by making running false like so:
-- // Varibles local ComputerScreen = game.Workspace.Computer.ComputerScreen local Decal = game.Workspace.Computer.ComputerScreen.Decal local TicketButton = game.Workspace.ComputerScreen.SurfaceGui.TicketButton local running = true --------------------------------------------------------------------------------- -- // Script while running do game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4652375883" wait(0.5) game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4648289865" wait(0.5) game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4652374880" end TicketButton.ClickDetector.MouseClick:Connect(function() game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=0" TicketButton.BackgroundTransparency = 0 TicketButton.TextTransparency = 0 end) TicketButton.ClickDetector.MouseClick:Connect(function() game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=0" TicketButton.BackgroundTransparency = 0 TicketButton.TextTransparency = 0 running = false end)
If you want the loop to start up again when clicked, then instead of saying running = false
say running = not running
which sets running
to the opposite value it was already at.
Create a marker to check when you press the button like this:
local clicked = false while true do if clicked == false then game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4652375883" wait(0.5) game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4648289865" wait(0.5) game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=4652374880" else break end end TicketButton.ClickDetector.MouseClick:Connect(function() clicked = true game.Workspace.Computer.ComputerScreen.Decal.Texture = "http://www.roblox.com/asset/?id=0" TicketButton.BackgroundTransparency = 0 TicketButton.TextTransparency = 0 end)
And my advise is if ever you want the changing frames to take less prossessing time and effort, instead of changing the Textures, in witch it will have to keep reloading every time, you can leave 3 decals loaded and set properties to visible/invisible.