Advertisement
LawMixer

PrimaryDoorHandler

Jul 28th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. local PlayersService = game:GetService("Players")
  2. local CollectionService = game:GetService("CollectionService")
  3. local DOORS = CollectionService:GetTagged("PrimaryDoor")
  4. local DoorModule = require(script.Parent.Parent.Libraries.DoorModule)
  5. local Permissions = require(script.Parent.Parent.Libraries.Permissions)
  6.  
  7. game.ReplicatedStorage.RemoteEvent.DoorSystem.OnServerEvent:Connect(function(player, doorModel, scannerModel)
  8. if not doorModel or not scannerModel then return false end
  9. if DoorModule.hasCooldown(doorModel) then return false end
  10. if not CollectionService:HasTag(doorModel, "PrimaryDoor") then return false end
  11. if doorModel:FindFirstChild("Configuration") == nil then return false end
  12. if doorModel.Configuration.DoorType.Value ~= script.Name then return false end
  13. if script.Parent.Parent.Libraries.Permissions:FindFirstChild(doorModel.Configuration.Permissions) == nil then return false end
  14. -- if not DoorModule.canSeeDoor(doorModel, player.Character) then return false end
  15.  
  16. local DoorConfiguration = DoorModule.returnDoorConfiguration(doorModel.Configuration.DoorType.Value)
  17. local DoorPermissions = Permissions.returnPermission(doorModel.Configuration.Permissions)
  18. print(DoorPermissions)
  19. if not DoorPermissions then return warn("[DoorSystem] Unknown Door Permission.") end
  20.  
  21. if not DoorPermissions.hasPermission(player) then
  22. scannerModel.PrimaryPart.Keycard_Denied:Play()
  23. scannerModel.PrimaryPart.Color = Color3.fromRGB(255, 0, 0)
  24. delay(2, function()
  25. if doorModel.Configuration.Lockdown.Value then scannerModel.PrimaryPart.Color = Color3.fromRGB(218, 133, 65) else scannerModel.PrimaryPart.Color = Color3.fromRGB(13, 105, 172) end
  26. end)
  27. DoorModule.setCooldown(doorModel, DoorConfiguration["Cooldown"])
  28. return false
  29. else
  30. scannerModel.PrimaryPart.Keycard_Accepted:Play()
  31. scannerModel.PrimaryPart.Color = Color3.fromRGB(0, 255, 0)
  32. delay(2, function()
  33. if doorModel.Configuration.Lockdown.Value then scannerModel.PrimaryPart.Color = Color3.fromRGB(218, 133, 65) else scannerModel.PrimaryPart.Color = Color3.fromRGB(13, 105, 172) end
  34. end)
  35. end
  36.  
  37. doorModel.Configuration.Open.Value = not doorModel.Configuration.Open.Value
  38. DoorModule.setCooldown(doorModel, DoorConfiguration["Cooldown"])
  39. end)
  40.  
  41. ----------------------------------------------------------------------------------------------------
  42. for _, Door in pairs(DOORS) do
  43. if not CollectionService:HasTag(Door, "PrimaryDoor") then return false end
  44. if Door:FindFirstChild("Configuration") == nil then return false end
  45. if Door.Configuration.DoorType.Value ~= script.Name then return false end
  46. if script.Parent.Parent.Libraries.Permissions:FindFirstChild(Door.Configuration.Permissions:GetChildren()) == nil then return false end
  47.  
  48. local DoorConfiguration = DoorModule.returnDoorConfiguration(Door.Configuration.DoorType.Value)
  49.  
  50. Door.Configuration.Open:GetPropertyChangedSignal("Value"):Connect(function()
  51. if Door.Configuration.Open.Value then
  52. Door.Door0.PrismaticConstraint.Speed = DoorConfiguration["OpenSpeed"]
  53. Door.Door0.PrismaticConstraint.TargetPosition = DoorConfiguration["OpenTarget"]
  54. Door.Door1.PrismaticConstraint.Speed = DoorConfiguration["OpenSpeed"]
  55. Door.Door1.PrismaticConstraint.TargetPosition = DoorConfiguration["OpenTarget"]
  56.  
  57. Door.Door0.Door_Open:Play() Door.Door0.Door_Close:Stop()
  58. else
  59. Door.Door0.PrismaticConstraint.Speed = DoorConfiguration["CloseSpeed"]
  60. Door.Door0.PrismaticConstraint.TargetPosition = DoorConfiguration["CloseTarget"]
  61. Door.Door1.PrismaticConstraint.Speed = DoorConfiguration["CloseSpeed"]
  62. Door.Door1.PrismaticConstraint.TargetPosition = DoorConfiguration["CloseTarget"]
  63.  
  64. Door.Door0.Door_Open:Stop() Door.Door0.Door_Close:Play()
  65. end
  66. end)
  67.  
  68. Door.Configuration.Lockdown:GetPropertyChangedSignal("Value"):Connect(function()
  69. if Door.Configuration.Lockdown.Value then
  70. for _, Scanner in pairs(Door:GetChildren()) do
  71. if CollectionService:HasTag(Scanner, "InteractionSystem") then Scanner.PrimaryPart.Color = Color3.fromRGB(218, 133, 65) end
  72. end
  73. else
  74. for _, Scanner in pairs(Door:GetChildren()) do
  75. if CollectionService:HasTag(Scanner, "InteractionSystem") then Scanner.PrimaryPart.Color = Color3.fromRGB(13, 105, 172) end
  76. end
  77. end
  78. end)
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement