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

5 comments

0

dont use ==, sometimes it skips by twos and goes off the until, then repeats forever, use >= or <=, they are better to use than ==

0

Yea but I need the value to be exact

0

Plus it just returns 19:06:25.987 - Players.H_exadecimal.PlayerGui.LocalScript:12: attempt to compare two userdata values

0

u break the loop

0

Do what greatneil said, it's gonna be nearly impossible to match up cframe unless you set it xD