I'm trying to make an animated E to open door script, but when I try to press e, on the output, it displays the error: "Workspace.Doors.Model.Main:5: attempt to index nil with 'Character'". Here is the script below:
local Can = true
local Open = false
script.Parent.Event.OnServerEvent:Connect(function(Player)
local Mag = (script.Parent.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Mag <= script.Parent.Range.Value then
if Can then
Can = false
if Open == false then
local Finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
for i = 0,1,.1 do
local CFM = script.Parent.PrimaryPart.CFrame:lertp(Finish,i)
script.Parent:SetPrimaryPartCFrame(CFM)
wait()
end
Open = true
else
Open = false
local Finish = script.Parent.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
for i = 0,1,.1 do
local CFM = script.Parent.PrimaryPart.CFrame:lertp(Finish,i)
script.Parent:SetPrimaryPartCFrame(CFM)
wait()
end
end
Can = true
end
end
end)
According to the error, this is the line that triggers the error:
local Mag = (script.Parent.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
This is a similar post to another post I made, which I tried to fix but did not work. Can someone help me out why this occurs? Thanks!

2 comments
Maybe write Lerp instead of lertp?
And also try to use TweenService as well and see if that is better