Still have questions? Join our Discord server and get real time help.
0

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

Edited 2 years ago

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


1
Try adding a wait() right above the last end Impacthills 223 — 2y
0
why are you making your event inside loop?,you don't need 2 loop for this script TheSkyofIndia 150 — 2y

0
Edited 2 years ago

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??