Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Function keeps repeating over and over again during a for loop, how do I fix this?

Asked by 4 years ago

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.


local doors = workspace.Doors local humRoot = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart", 10) while wait() do for _,v in pairs(doors:GetChildren()) do if (v.Hinge.Position - humRoot.Position).magnitude <= 15 then repeat wait() for i = 1,90 do wait() v.Part.CFrame = v.Hinge.CFrame * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(2.5,0,0) end until v.Part.CFrame == v.Hinge.CFrame * CFrame.Angles(0, math.rad(90), 0) * CFrame.new(2.5,0,0) break else v.Part.CFrame = v.Hinge.CFrame * CFrame.Angles(0,0,0) * CFrame.new(2.5,0,0) end end end
0
dont use ==, sometimes it skips by twos and goes off the until, then repeats forever, use >= or <=, they are better to use than == greatneil80 2647 — 4y
0
Yea but I need the value to be exact H_exadecimal 9 — 4y
0
Plus it just returns 19:06:25.987 - Players.H_exadecimal.PlayerGui.LocalScript:12: attempt to compare two userdata values H_exadecimal 9 — 4y
0
u break the loop TheluaBanana 946 — 4y
0
Do what greatneil said, it's gonna be nearly impossible to match up cframe unless you set it xD BlackOrange3343 2676 — 4y

Answer this question