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 5 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.

01local doors = workspace.Doors
02local humRoot = game:GetService("Players").LocalPlayer.Character:WaitForChild("HumanoidRootPart", 10)
03while wait() do
04    for _,v in pairs(doors:GetChildren()) do
05        if (v.Hinge.Position - humRoot.Position).magnitude <= 15 then
06            repeat wait()
07                for i = 1,90 do
08                wait()
09                v.Part.CFrame = v.Hinge.CFrame * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(2.5,0,0)
10            end
11            until
12            v.Part.CFrame == v.Hinge.CFrame * CFrame.Angles(0, math.rad(90), 0) * CFrame.new(2.5,0,0)
13            break
14        else
15            v.Part.CFrame = v.Hinge.CFrame * CFrame.Angles(0,0,0) * CFrame.new(2.5,0,0)
16        end
17    end
18end
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 — 5y
0
Yea but I need the value to be exact H_exadecimal 9 — 5y
0
Plus it just returns 19:06:25.987 - Players.H_exadecimal.PlayerGui.LocalScript:12: attempt to compare two userdata values H_exadecimal 9 — 5y
0
u break the loop TheluaBanana 946 — 5y
0
Do what greatneil said, it's gonna be nearly impossible to match up cframe unless you set it xD BlackOrange3343 2676 — 5y

Answer this question