Why is this bugging out the whole door?

I have a keybind door script that you close the door manually with F and open it. However, I later added a system so if you did not close the door in 2 seconds, it will close the door itself.

I’ve found that even though the script works, spamming F or continuously opening the door for 2 seconds eventually it goes back another -90 degrees. I’m pretty sure its that after 2 seconds is over, if Open is true for a quick moment then it will close the door another -90 degrees backwards.

I’ve looked around and couldn’t find anything that helps this.

If there is a more reasonble way of making a keybind door script make sure to let me know. This is only on the server side, the local side is working fine.

local Can = true
local Open = false
local dooropen = script.Parent.door_open
local doorclose = script.Parent.door_close
local gamegui = script.Parent.Center.GameGui.TextLabel

L_1_ = script.Parent
L_2_ = L_1_.Parent
L_3_ = L_2_.Door.Config.Range.Value

script.Parent.ChangeDoorStateEvent.OnServerEvent:connect(function(Player)
	local Mag = (L_1_.Center.Position - Player.Character.HumanoidRootPart.Position).Magnitude
	if Mag <= L_3_ then
		if Can then
			Can = false
if Open == false then
	doorclose:Stop()
	dooropen:Play()
	gamegui.Text = "Close"
	local Finish = L_1_.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(95),0)
	for i=0,1,.1 do
		local CFm = L_1_.PrimaryPart.CFrame:lerp(Finish,i)
		L_1_:SetPrimaryPartCFrame(CFm)
		wait(0.01)
	end
	Open = true
	
		else
			Open = false
				dooropen:Stop()
				doorclose:Play()
				gamegui.Text = "Open"
				local Finish = L_1_.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-95),0)
				for i=0,1,.1 do
					local CFm = L_1_.PrimaryPart.CFrame:lerp(Finish,i)
					L_1_:SetPrimaryPartCFrame(CFm)
					wait(0.01)
				end
			end
			Can = true
			end
		end
	
    if Open then
	wait(2)
	Open = false
	doorclose:Play()
	gamegui.Text = "Open"
        local Finish = L_1_.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-95),0)
        for i=0,1,.1 do
	       	local Cfm = L_1_.PrimaryPart.CFrame:lerp(Finish,i)
		    L_1_:SetPrimaryPartCFrame(Cfm)
		wait(0.01)
		gamegui.Text = "Open"
        end
	Can = true
	end
end)

Sorry for spacing it weird, I need to learn how to correctly space scripts.

Here is the place that closes the door automatically after 2 seconds.

  if Open then
	wait(2)
	Open = false
	doorclose:Play()
	gamegui.Text = "Open"
        local Finish = L_1_.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-95),0)
        for i=0,1,.1 do
	       	local Cfm = L_1_.PrimaryPart.CFrame:lerp(Finish,i)
		    L_1_:SetPrimaryPartCFrame(Cfm)
		wait(0.01)
		gamegui.Text = "Open"
        end
	Can = true
	end
end)

Anything helps! Thanks. :smile:

3 Likes

You should check if it’s open after waiting 2 seconds instead of checking if it’s still open and then waiting 2 seconds.

spawn(function()
	wait(2)
	if Open then 
		doorclose:Play()
		gamegui.Text = "Open"
        local Finish = L_1_.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-95),0)
        for i=0,1,.1 do
	       	local Cfm = L_1_.PrimaryPart.CFrame:lerp(Finish,i)
		    L_1_:SetPrimaryPartCFrame(Cfm)
		wait(0.01)
		gamegui.Text = "Open"
        end
		Can = true
	end
end)
1 Like

Have you tried using a “Vertical Hinge” and adding the rest of the features you need via script? Should be more reliable.

I have noticed it is not glitching, however I have found a issue once opening then immediately closing it, it closes super fast. I think it might be that the timer is running even when open doesn’t equal true.

I have not, I can look into it. Thanks

1 Like

Set Open to true before starting the door animation and it should work.

Seemed to make it worse, it now completly glitches it out. I could try making Open = false right before the animation to close it happens. I could see if that can fix it.