So I’ve made these doors and I’m having some trouble with them in those cases where they are being used a lot.
I had people complain about it too, even though it isn’t something that happens really easily.
So the doors are supposed to rotate open and closed, and auto close after 10 seconds.
I believe that the problem is because the mix of while true do repeatedly checking for the timer.value to hit 0 and when it finally does, and somebody activates the click function right in that moment, the door somehow double rotates or doesn’t rotate properly. That’s the problem we’ve been having.
Here’s a picture of a door that is “closed” but is stuck in a wrong rotation.
So I’ve already made a solution myself and that was to add a variable to the door that says when the timer hits 0 and it’s time to auto close, do not let people use the door. The variable stops the door from working as soon as it hits 0 and I wanted to ask if there’s somebody that could help me go through this “solution” and if it should even work as it would take a while for me to replace this in different door scripts.
I was thinking if I should change it to so, whenever the timer.value is 1, variable should be true so that it kind of warms up the variable right before auto-close.
The original door script:
Summary
local Can = true
local Open = false
local Click = script.Parent.Part.ClickDetector
local Timer = script.Parent.Timer
local Knock = script.Parent.Center.Knock
local LS = game:GetService("Lighting")
local Unauth = game.Teams.Patient.TeamColor
local Max = game.Teams["Max Security Patient"].TeamColor
local Box = game.Teams["The Box"].TeamColor
local Solitary = game.Teams["Solitary Confinement"].TeamColor
local Cooldown = 0
local GlobalSchedule = LS.Schedule
Click.MouseClick:Connect(function(Player)
if GlobalSchedule.Value == 3 and Player.TeamColor == Unauth or GlobalSchedule.Value == 3 and Player.TeamColor == Max or GlobalSchedule.Value == 4 and Player.TeamColor == Unauth or GlobalSchedule.Value == 4 and Player.TeamColor == Max or GlobalSchedule.Value == 3 and Player.TeamColor == Box or GlobalSchedule.Value == 3 and Player.TeamColor == Solitary or GlobalSchedule.Value == 4 and Player.TeamColor == Box or GlobalSchedule.Value == 4 and Player.TeamColor == Solitary then
if Player.TeamColor == Unauth and Cooldown == 0 or Player.TeamColor == Max and Cooldown == 0 then
Cooldown = 5
Knock:Play()
wait(2)
Cooldown = 0
elseif Player.TeamColor == Unauth and Cooldown == 5 or Player.TeamColor == Max and Cooldown == 5 then
return
end
else
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
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:lerp(finish,i)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end
Open = true
Timer.Value = 10
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:lerp(finish,i)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end
end
Can = true
end
end
end
end)
while true do
while Timer.Value > 0 do
Timer.Value = Timer.Value - 1
wait(1)
end
if Open == true and Timer.Value == 0 then
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:lerp(finish,i)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end
Can = true
end
wait()
end
The scripted solution:
Summary
local Can = true
local Open = false
local Bug = false
local Click = script.Parent.Part.ClickDetector
local Timer = script.Parent.Timer
local Knock = script.Parent.Center.Knock
local LS = game:GetService("Lighting")
local Unauth = game.Teams.Patient.TeamColor
local Max = game.Teams["Max Security Patient"].TeamColor
local Box = game.Teams["The Box"].TeamColor
local Solitary = game.Teams["Solitary Confinement"].TeamColor
local Cooldown = 0
local GlobalSchedule = LS.Schedule
Click.MouseClick:Connect(function(Player)
if GlobalSchedule.Value == 3 and Player.TeamColor == Unauth or GlobalSchedule.Value == 3 and Player.TeamColor == Max or GlobalSchedule.Value == 4 and Player.TeamColor == Unauth or GlobalSchedule.Value == 4 and Player.TeamColor == Max or GlobalSchedule.Value == 3 and Player.TeamColor == Box or GlobalSchedule.Value == 3 and Player.TeamColor == Solitary or GlobalSchedule.Value == 4 and Player.TeamColor == Box or GlobalSchedule.Value == 4 and Player.TeamColor == Solitary then
if Player.TeamColor == Unauth and Cooldown == 0 or Player.TeamColor == Max and Cooldown == 0 then
Cooldown = 5
Knock:Play()
wait(2)
Cooldown = 0
elseif Player.TeamColor == Unauth and Cooldown == 5 or Player.TeamColor == Max and Cooldown == 5 then
return
end
else
if Bug == true then
return
end
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
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:lerp(finish,i)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end
Open = true
Timer.Value = 10
else
if Bug == true then
return
end
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:lerp(finish,i)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end
end
Can = true
end
end
end
end)
while true do
while Timer.Value > 0 do
Timer.Value = Timer.Value - 1
wait(1)
end
if Open == true and Timer.Value == 0 then
Bug = true
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:lerp(finish,i)
script.Parent:SetPrimaryPartCFrame(cfm)
wait()
end
Can = true
wait(.25)
Bug = false
end
wait()
end
Sorry if the script is kind of messy.