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

Loop inside of loop kills my game and I don't know why?

I'm experimenting with loops inside of loops and this is my first attempt, but when I click, Studio will always crash and I don't know why. Here is script:

loop = 1

while true do
	while loop < 8 do
	wait(1)
	script.Parent.Parent.HingeConstraint.TargetAngle = script.Parent.Parent.HingeConstraint.TargetAngle - 6
	loop = math.random(1,10)
end

local CD = script.Parent -- Clickdetector

CD.MouseClick:connect(function(click)
        loop = math.random(1,7)
end)
end

2 comments

1

Try adding a wait() right above the last end

0

why are you making your event inside loop?,you don't need 2 loop for this script

1 answer

An event will be activated when it's... activated.

You don't need a loop for that, also you forgot a wait() wich can also break your script.

loop = 1
local CD = script.Parent -- Clickdetector

while true do
	wait()
    while loop < 8 do
   	 wait(1)
         script.Parent.Parent.HingeConstraint.TargetAngle = 			 script.Parent.Parent.HingeConstraint.TargetAngle - 6
         loop = math.random(1,10)
    end
end

CD.MouseClick:connect(function(click)
        loop = math.random(1,7)
end)

Also, why do you have two loops inside each other??

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