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.