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. ![]()