For some reason, this door doesn't stop rotating at 90 degrees; it just keeps spinning and spinning. I think it has something to do with heartbeat, but what I was trying to do was make the door lerp smoothly using heartbeat, to the 90 degree mark. Here's a GIF of what it looks like:
https://gyazo.com/3633367499479c724ec662fe3ce17896
Here's the script:
local Can = true
local Open = false
script.Parent.Event.OnServerEvent:connect(function(Player)
local Mag = (script.Parent.Center.Position-Player.Character.HumanoidRootPart.Position).magnitude
if Mag <= script.Parent.Range.Value then
if Can then
Can = false
if Open == false then
game:GetService('RunService').Heartbeat:Connect(function(d)
local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,d*2)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end)
Open = true
else
Open = false
game:GetService('RunService').Heartbeat:Connect(function(d)
local finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
local cfm = script.Parent.PrimaryPart.CFrame:lerp(finish,d*2)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end)
end
Can = true
end
end
end)
Can someone tell me what's wrong? I'll fix it; but I just need to know what to fix first.

2 comments
How long do you want the opening to last?
if it doesn't work, try using my model for help or something --> https://www.roblox.com/library/4559559581/Door