Multi use doors not working

I want to create a easy door system for all platforms.
But its not working because the server focus’s on one door at a time which causes the first door then next door order I don’t want, I want the any door order.

DoorModule:

--Client-side version for the DoorModule

local GuiService = game:GetService("GuiService")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera

--Important functions

local function IsLessThan(v1, v2)
	--Thanks HugeCoolboy2007!
	return (v1.X < v2.X) and (v1.Y < v2.Y)
end

--Device checkers

local function CheckIfGamepad()
	--GuiService.SelectedObject is used for gamepads and xbox does so.
	if GuiService.SelectedObject ~= nil then
		return true
	end

	return false
end

local function CheckIfXbox()
	local IsGamepad = CheckIfGamepad() or UserInputService.GamepadEnabled

	if IsGamepad then
		if Camera.ViewportSize == Vector2.new(1920, 1080) or IsLessThan(Camera.ViewportSize, Vector2.new(1920, 1080)) then
			return true
		end
	end

	return false
end

local function CheckIfPhone()
	local TouchEnabled = UserInputService.TouchEnabled

	if TouchEnabled then
		if Camera.ViewportSize == Vector2.new(852, 414) or IsLessThan(Camera.ViewportSize, Vector2.new(852, 414)) then
			return true
		end
	end

	return false
end

local function CheckIfTablet()
	local TouchEnabled = UserInputService.TouchEnabled

	if TouchEnabled then
		if Camera.ViewportSize == Vector2.new(1280, 800) or IsLessThan(Camera.ViewportSize, Vector2.new(1280, 800)) then
			return true
		end
	end

	return false
end

local t = {}

t.SetupDoor = function(Door, KeyBindFunc)
	--Sets up the door keybinding functions, tag and UI.
	
	local KeyVal = Instance.new("StringValue") --Tag
	KeyVal.Name = "KeyVal"
	KeyVal.Value = HttpService:GenerateGUID(true)
	KeyVal.Parent = Door

	local IsXbox = CheckIfXbox()
	local IsPhone = CheckIfPhone()
	local IsTablet = CheckIfTablet()

	local UiKey = Door.UiKey
	local UiXboxKey = Door.UiXboxKey

	if IsXbox or UserInputService.GamepadEnabled then
		--Xbox and Gamepad mode
		UiKey.Enabled = false
		UiXboxKey.Enabled = true

		ContextActionService:BindAction("DoorKeybind-"..KeyVal.Value, KeyBindFunc, false, Enum.KeyCode.ButtonB, Enum.KeyCode.ButtonL1)
	elseif IsPhone then
		--Phone
		UiKey.Enabled = true
		UiXboxKey.Enabled = false

		UiKey.Key.Visible = false

		ContextActionService:BindAction("DoorKeybind-"..KeyVal.Value, KeyBindFunc, true)
	elseif IsTablet then
		--Tablet
		UiKey.Enabled = true
		UiXboxKey.Enabled = false

		UiKey.Key.Visible = false

		UiKey.Tap.Position = UDim2.new(0.05, 0, 0.05, 0)
		UiKey.Tap.Size = UDim2.new(0.9, 0, 0.9, 0)

		ContextActionService:BindAction("DoorKeybind-"..KeyVal.Value, KeyBindFunc, true)
	else
		--PC
		UiKey.Enabled = true
		UiXboxKey.Enabled = false

		UiKey.Tap.Visible = false

		ContextActionService:BindAction("DoorKeybind-"..KeyVal.Value, KeyBindFunc, false, Enum.KeyCode.E)
	end
end

t.CreateClientDoor = function(Door)
	--This is important for the door to work with custom guis

	t.SetupDoor(Door, function()
		--Disables the door
		
		local ShouldDisableKeybind = ReplicatedStorage.GetDoorLog:InvokeServer(Door.Name)
		
		if ShouldDisableKeybind then
			ContextActionService:UnbindAction("DoorKeybind-"..Door.KeyVal.Value)
			ReplicatedStorage.OpenDoor:FireServer(Door.Name)
		end
	end)
end

--Unused
--ReplicatedStorage.ClientCreateDoor.OnClientEvent:Connect(function(Door)
--	t.CreateClientDoor(Door)
--end)

return t

DoorHandler:

local ReplicatedStorage = game:WaitForChild("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local DoorTweenInfo = TweenInfo.new(
	1.222,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.Out,
	0,
	false,
	0.1
)
local DoorsNumber = 0

ReplicatedStorage.OpenDoor.OnServerEvent:Connect(function(Player, DoorName)
	local Door = workspace.Doors[DoorName]
	if not Door.Opened.Value then
		Door.Opened.Value = true
		Door.UiKey:Destroy()
		Door.UiXboxKey:Destroy()
		
		local Tween = TweenService:Create(Door, DoorTweenInfo, {CFrame = Door.DoorOpen.CFrame})
		Door.OpenSound:Play()
		Tween:Play()
		
		Tween.Completed:Connect(function()
			Tween:Cancel()
			Tween = nil
		end)
	end
end)

ReplicatedStorage.GetDoorLog.OnServerInvoke = function(Player, DoorName)
	local Door = workspace.Doors[DoorName]
	local Character = Player.Character

	local HRP = Character.HumanoidRootPart

	local Distance = (HRP.Position - Door.Position).Magnitude

	if Distance < 5 then
		return true
	else
		return false
	end
end

--ReplicatedStorage.CreateDoor.Event:Connect(function(CF)
--	DoorsNumber += 1
--	local Door = ServerStorage.Door:Clone()
--	Door.Name = "Door-"..DoorsNumber
--	Door.CFrame = CF
--	Door.Parent = workspace.Doors
	
--	ReplicatedStorage.ClientCreateDoor:FireAllClients(Door)
--end)

--require(ReplicatedStorage.Server.RoomsSystem).CreateRoom()

Sorry for the bad quality

Video of the bug:
robloxapp-20221226-1825580.wmv (2.5 MB)

I’m using a gamepad to control the character by the way.

1 Like

Sorry, don’t quite understand what you mean.

The order of any door you open. In this case there is a order when I don’t want a order.

Why do you cancel a tween, when it’s completed?

Also do you want all the doors to open at the same time, or what’s your goal?

My goal is whatever door the player chooses that door opens no matter the order.

Why are you telling me about “the order”. Should they have an order at all? Are they linked in any way? Do you want all the doors just to be independant working doors?

Independent working doors connected to the same module script.

Loop through all the doors. And think of it like you’re making 1 door. You can even define a dictionary with data like, what part activates the door ect.

local Doors = {
	Door1 = {DoorModel=DefineYourself, DoorActivator=DefineYourself2}
}

for _, Data in pairs(Doors) do
	Data.DoorActivator.Touched:Connect(function(hit)
		-- If hit is player, then tween door open/closed
		Data.DoorModel:TweenThisNow -- Just a sample
	end
end

doorStuff:

--Makes anything in the door folder work.
--This is client-sided not server-sided so hackers could break the system.
--But thats never gonna happen!

--WARNING:This system uses Server-Client remote functions meaning doors could break if anything is wrong with the DoorHandler or DoorModule.

for _,v in pairs(workspace.Doors:GetChildren()) do
	require(game:GetService("ReplicatedStorage").Client.DoorModule).CreateClientDoor(v)
end

I changed my mind about this, I don’t want independent working doors now.

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