making a system for doors in a friend’s game, and making it so if a player is in a sensor range the door will open, and remain open until they go through or leave.
BUT
it partially breaks the door if you repeatedly go in and out of the sensor, and I’m not sure how I can prevent this…
Example :
Also the part of the modulescript for controlling the doors:
BMRF_Doors = function(Door) --formerly black mesa doors remade but now original doors lol
local DoorOpen = false
local Cooldown = false
local HitTable = {}
local function CheckForClose()
if #HitTable < 1 then
DoorOpen = false
ModelTween:TweenModel(Door.Door1,Door.Positions.Door1.Shut.CFrame,0.8,{Direction=Enum.EasingDirection.InOut,Style=Enum.EasingStyle.Quad})
ModelTween:TweenModel(Door.Door2,Door.Positions.Door2.Shut.CFrame,0.8,{Direction=Enum.EasingDirection.InOut,Style=Enum.EasingStyle.Quad})
Door.Sensor.Close:Play()
task.wait(0.7)
end
end
Door.Sensor.Touched:Connect(function(Obj)
local player = game.Players:GetPlayerFromCharacter(Obj.Parent)
if player and player.Character and player.Character.PrimaryPart == Obj then
if not table.find(HitTable,player.UserId) then
table.insert(HitTable,player.UserId)
end
if not DoorOpen then
Door.Sensor.Close:Stop()
Door.Sensor.Open:Play()
ModelTween:TweenModel(Door.Door1,Door.Positions.Door1.Open.CFrame,0.8,{Direction=Enum.EasingDirection.InOut,Style=Enum.EasingStyle.Quad})
ModelTween:TweenModel(Door.Door2,Door.Positions.Door2.Open.CFrame,0.8,{Direction=Enum.EasingDirection.InOut,Style=Enum.EasingStyle.Quad})
task.wait(0.8)
Door.Sensor.Open:Stop()
DoorOpen = true
CheckForClose()
end
end
end)
Door.Sensor.TouchEnded:Connect(function(Obj)
local player = game.Players:GetPlayerFromCharacter(Obj.Parent)
if player and player.Character and player.Character.PrimaryPart == Obj then
local index = table.find(HitTable,player.UserId)
if index then
table.remove(HitTable,index)
end
if DoorOpen then
CheckForClose()
end
end
end)
end,