epicguest

Untitled

Feb 28th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. -- Services
  2.  
  3. local Players = game:GetService("Players")
  4. local TS = game:GetService("TweenService")
  5. local ReSt = game:GetService("ReplicatedStorage")
  6.  
  7. -- Variables
  8.  
  9. local Plr = Players.LocalPlayer
  10. local Char = Plr.Character or Plr.CharacterAdded:Wait()
  11. local Hum = Char:WaitForChild("Humanoid")
  12. local Root = Char:WaitForChild("HumanoidRootPart")
  13.  
  14. local SelfModules = {
  15. Functions = loadstring(game:HttpGet("https://raw.githubusercontent.com/RegularVynixu/Utilities/main/Functions.lua"))(),
  16. }
  17.  
  18. local Assets = {
  19. Door = game:GetObjects("rbxassetid://11850776315")[1],
  20. }
  21.  
  22. local DoorReplication = {}
  23.  
  24. -- Misc Functions
  25.  
  26. local function openDoor(doorTable)
  27. doorTable.Debug.OnDoorPreOpened()
  28. doorTable.Model:SetAttribute("Opened", true)
  29.  
  30. if doorTable.Model:FindFirstChild("Lock") then
  31. -- Unlock visual
  32.  
  33. doorTable.Model.Lock.Base.UnlockPrompt.Enabled = false
  34. doorTable.Model.Lock.Base.UnlockPrompt:Destroy()
  35. end
  36.  
  37. -- Door opening visual
  38.  
  39. if doorTable.Model:FindFirstChild("Light") then
  40. doorTable.Model.Light.Light.Color = Color3.fromRGB(197, 113, 88)
  41. doorTable.Model.Light.Light.Attachment.PointLight.Enabled = true
  42. doorTable.Model.Light.Light.Hit:Play()
  43. end
  44.  
  45. doorTable.Model.Door.CanCollide = false
  46. doorTable.Model.Door.Open:Play()
  47. doorTable.Model.Hidden:Destroy()
  48.  
  49. task.spawn(function()
  50. local knobC1 = doorTable.Model.Hinge.Knob.C1
  51.  
  52. TS:Create(doorTable.Model.Hinge.Knob, TweenInfo.new(0.15, Enum.EasingStyle.Quad), {C1 = knobC1 * CFrame.Angles(0, 0, math.rad(-35))}):Play()
  53. task.wait(0.15)
  54. TS:Create(doorTable.Model.Hinge.Knob, TweenInfo.new(0.15, Enum.EasingStyle.Quad), {C1 = knobC1}):Play()
  55. end)
  56.  
  57. TS:Create(doorTable.Model.Hinge, TweenInfo.new(doorTable.Config.FastOpen and 0.15 or 0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {CFrame = doorTable.Model.Hinge.CFrame * CFrame.Angles(0, math.rad(-90), 0)}):Play()
  58.  
  59. -- Next room preparations
  60.  
  61. local nextRoom = workspace.CurrentRooms:FindFirstChild(tonumber(doorTable.Model.Parent.Name) + 1)
  62.  
  63. if nextRoom then
  64. for _, v in next, {"Assets", "Light_Fixtures"} do
  65. if nextRoom:FindFirstChild(v) then
  66. for _, v2 in next, nextRoom[v]:GetDescendants() do
  67. if string.find(v2.ClassName, "Light") and not v2.Enabled then
  68. v2.Enabled = true
  69. end
  70. end
  71. end
  72. end
  73. end
  74.  
  75. doorTable.Debug.OnDoorOpened()
  76. end
  77.  
  78. -- Functions
  79.  
  80. DoorReplication.CreateDoor = function(config)
  81. -- Configs setup
  82.  
  83. for _, v in next, {"Key", "Lockpick"} do
  84. if not table.find(config.CustomKeyNames, v) then
  85. table.insert(config.CustomKeyNames, v)
  86. end
  87. end
  88.  
  89. -- Model
  90.  
  91. local model = Assets.Door:Clone()
  92. model.Door.MaterialVariant = "PlywoodALT"
  93. model.Sign.MaterialVariant = "Plywood"
  94.  
  95. if not config.Barricaded then
  96. model.Boards:Destroy()
  97.  
  98. if not config.Locked then
  99. model.Lock:Destroy()
  100. end
  101.  
  102. if config.Sign == false then
  103. model.Sign:Destroy()
  104. model.Gui:Destroy()
  105. end
  106.  
  107. if config.Light == false then
  108. model.Light:Destroy()
  109. end
  110. else
  111. model.Lock:Destroy()
  112. model.Sign:Destroy()
  113. model.Gui:Destroy()
  114. end
  115.  
  116. return {
  117. Model = model,
  118. Config = config,
  119. Debug = {
  120. OnDoorPreOpened = function() end,
  121. OnDoorOpened = function() end,
  122. },
  123. }
  124. end
  125.  
  126. DoorReplication.ReplicateDoor = function(doorTable)
  127. -- Pre-check
  128.  
  129. if not doorTable.Model.Parent then
  130. warn("Failure - Parent the door before replicating it")
  131. return
  132.  
  133. elseif doorTable.Config.Barricaded then
  134. warn("Failure - Attempt to replicate a barricaded door")
  135. return
  136. end
  137.  
  138. -- Guiding light
  139.  
  140. if doorTable.Config.GuidingLight ~= false and doorTable.Model.Parent:GetAttribute("IsDark") then
  141. task.spawn(function()
  142. if not doorTable.Model.Door.LightAttach.HelpLight.Enabled then
  143. task.wait(15)
  144. end
  145.  
  146. if doorTable.Model.Parent and not doorTable.Model:GetAttribute("Opened") then
  147. doorTable.Model.Door.LightAttach.HelpLight.Enabled = true
  148. doorTable.Model.Door.LightAttach.HelpParticle.Enabled = true
  149.  
  150. TS:Create(doorTable.Model.Door.LightAttach.HelpLight, TweenInfo.new(2), {Brightness = 0.5}):Play()
  151. end
  152. end)
  153. end
  154.  
  155. -- Connections
  156.  
  157. local connections = {}
  158.  
  159. if doorTable.Model:FindFirstChild("Lock") then
  160. connections.unlockBegan = doorTable.Model.Lock.Base.UnlockPrompt.PromptButtonHoldBegan:Connect(function()
  161. for _, v in next, doorTable.Config.CustomKeyNames do
  162. local key = Char:FindFirstChild(v)
  163.  
  164. if key and key:FindFirstChild("Animations") and key.Animations:FindFirstChild("use") then
  165. Hum:LoadAnimation(key.Animations.use):Play()
  166.  
  167. return
  168. end
  169. end
  170.  
  171. firesignal(ReSt.Bricks.Caption.OnClientEvent, "You need a key!", true)
  172. end)
  173.  
  174. connections.unlockTriggered = doorTable.Model.Lock.Base.UnlockPrompt.Triggered:Connect(function()
  175. for _, v in next, doorTable.Config.CustomKeyNames do
  176. local key = Char:FindFirstChild(v)
  177.  
  178. if key then
  179. for _, v in next, connections do
  180. v:Disconnect()
  181. end
  182.  
  183. if doorTable.Config.DestroyKey ~= false then
  184. key:Destroy()
  185. end
  186.  
  187. openDoor(doorTable)
  188.  
  189. break
  190. end
  191. end
  192. end)
  193. else
  194. task.spawn(function()
  195. while doorTable.Model.Parent and Root do
  196. if (Root.Position - doorTable.Model.PrimaryPart.Position).Magnitude <= 15 then
  197. openDoor(doorTable)
  198.  
  199. break
  200. end
  201.  
  202. task.wait()
  203. end
  204. end)
  205. end
  206. end
  207.  
  208. -- Scripts
  209.  
  210. return DoorReplication
Add Comment
Please, Sign In to add comment