Function keeps repeating over and over again during a for loop, how do I fix this?
So I am trying to make it where you get near a model and it rotates the part around a certain point. It works fine, but it repeats until the players magnitude is out of the limit. I tried using repeat until and if else statements but it still does not work perfectly.
01 | local doors = workspace.Doors |
02 | local humRoot = game:GetService( "Players" ).LocalPlayer.Character:WaitForChild( "HumanoidRootPart" , 10 ) |
04 | for _,v in pairs (doors:GetChildren()) do |
05 | if (v.Hinge.Position - humRoot.Position).magnitude < = 15 then |
09 | v.Part.CFrame = v.Hinge.CFrame * CFrame.Angles( 0 , math.rad(i), 0 ) * CFrame.new( 2.5 , 0 , 0 ) |
12 | v.Part.CFrame = = v.Hinge.CFrame * CFrame.Angles( 0 , math.rad( 90 ), 0 ) * CFrame.new( 2.5 , 0 , 0 ) |
15 | v.Part.CFrame = v.Hinge.CFrame * CFrame.Angles( 0 , 0 , 0 ) * CFrame.new( 2.5 , 0 , 0 ) |