Help with a automatic door system

I have made an automatic door system but it seems that only one player can use the doors without them glitching. Here is the localscript for managing them. Also, I am using bridgenet.

local BridgeNet = require(RepStorage.BridgeNet)

local Closed = true

local Open = BridgeNet.CreateBridge("DoorOpen")
local Close = BridgeNet.CreateBridge("DoorClose")

local Doors = workspace.SlidingDoors:GetChildren()
local Gates = workspace.GateDoors:GetChildren()

game:GetService("RunService").RenderStepped:Connect(function()
	for _, door in pairs(Doors) do
		task.wait(.5)
		local OpenSound = door.Hitbox.Open
		local CloseSound = door.Hitbox.Close
		
		local IsTouching = false
		local Region = Region3.new(door.Hitbox.Position - (door.Hitbox.Size/2), door.Hitbox.Position + (door.Hitbox.Size/2))

		local Parts = game.Workspace:FindPartsInRegion3WithWhiteList(Region, game.Players.LocalPlayer.Character:GetChildren())

		for _, RegionPart in pairs(Parts) do
			if RegionPart:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				IsTouching = true
			end
		end
		if IsTouching then
			Open:Fire(door.Name)
		else
			Close:Fire(door.Name)
			--CloseSound:Play()
		end
	end
	
	for _, gate in pairs(Gates) do
		task.wait(.5)

		local IsTouching = false
		local Region = Region3.new(gate.Hitbox.Position - (gate.Hitbox.Size/2), gate.Hitbox.Position + (gate.Hitbox.Size/2))

		local Parts = game.Workspace:FindPartsInRegion3WithWhiteList(Region, game.Players.LocalPlayer.Character:GetChildren())

		for _, RegionPart in pairs(Parts) do
			if RegionPart:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				IsTouching = true
			end
		end
		if IsTouching then
			Open:Fire(gate.Name)
			Closed = false
		else
			if not Closed then
				Close:Fire(gate.Name)
				Closed = true
			end
			--CloseSound:Play()
		end
	end
end)

Help would be greatly appreciated.

1 Like

Also here is a game place with the doors
autodoors.rbxl (78.0 KB)

Please, someone, help with this

So if I read your message clearly, the door glitches when more than one person is using it. Since this is the case you could basically have a debounce for when it opens. You simply create a variable that stores your boolean. Have a condition that checks if the variable is false and when it is inside the condition make your variable set to true. This will make your condition not pass through since it needs your variable boolean set to true, therefore your door won’t open anymore. You can simply set your boolean reference (variable) to false when needed whenever you want to allow the door to open again.

2 Likes

u should detect using a touch event for each door(via Touched and TouchEnded) instead of a region. also just like what JonBonesJones said, add a debounce

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.