I actually don’t know the best way to finish this script, in my working version of the script, it works perfectly, but sometimes the character plays the animation but the door don’t open, so i’m trying to fix it, I don’t have idea to what to do.
local Can=true
local Open=false
sc=script.Parent
sc.Event.OnServerEvent:connect(function(Player)
local speed=Player.Character.Humanoid.Running:connect(Player) --if i remove that, it works perfectly
local Mag=(sc.Center.Position-Player.Character.IntPoint.Position).magnitude
if Mag<=sc.range.Value and speed<=0 then
if Can then
Can=false
if Open==false then
sc.Center.open:Play()
local finish=sc.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(80),0)
for i=0,0.6,.05 do
local cfm=sc.PrimaryPart.CFrame:lerp(finish,i)
sc:SetPrimaryPartCFrame(cfm)
wait(0.01)
end
Open=true
else
Open=false
sc.Center.close:Play()
local finish=sc.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(80),0)
for i=0,0.6,.05 do
local cfm=sc.PrimaryPart.CFrame:lerp(finish,i)
sc:SetPrimaryPartCFrame(cfm)
wait(0.01)
end
end
Can=true
end
end
end)