Hasli4

Untitled

Oct 28th, 2026
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. local TweenService = game:GetService("TweenService")
  2.  
  3. -- Настройки сундука
  4. local Config = {
  5. OpenAnimation = {
  6. Duration = 0.4,
  7. EasingStyle = Enum.EasingStyle.Sine,
  8. EasingDirection = Enum.EasingDirection.Out,
  9. Angle = 80
  10. },
  11.  
  12. CloseAnimation = {
  13. Duration = 0.7,
  14. EasingStyle = Enum.EasingStyle.Bounce,
  15. EasingDirection = Enum.EasingDirection.Out,
  16. Angle = -80
  17. },
  18.  
  19. ProximityPrompt = {
  20. DefaultDistance = 5,
  21. OpenedDistance = 12
  22. },
  23.  
  24. Sounds = {
  25. OpenSoundId = nil,
  26. CloseSoundId = nil
  27. }
  28. }
  29.  
  30. -- Объекты сундука
  31. local Chest = script.Parent
  32. local Prompt = Chest.Structure.Trigger.ProximityPrompt
  33. local Hinge = Chest.Structure:WaitForChild("Hinge")
  34.  
  35. local Opened = false
  36. local Busy = false
  37.  
  38. -- Создание звуков, если указаны их ID
  39. local OpenSound
  40. local CloseSound
  41.  
  42. if Config.Sounds.OpenSoundId then
  43. OpenSound = Instance.new("Sound")
  44. OpenSound.Parent = Hinge
  45. OpenSound.SoundId = Config.Sounds.OpenSoundId
  46. OpenSound.Volume = 1
  47. end
  48.  
  49. if Config.Sounds.CloseSoundId then
  50. CloseSound = Instance.new("Sound")
  51. CloseSound.Parent = Hinge
  52. CloseSound.SoundId = Config.Sounds.CloseSoundId
  53. CloseSound.Volume = 1
  54. end
  55.  
  56. local function PlaySound(sound)
  57. if sound then
  58. sound:Play()
  59. end
  60. end
  61.  
  62. -- Проверяем, есть ли у игрока нужный Tool
  63. local function PlayerHasKey(player)
  64. local backpack = player:FindFirstChildOfClass("Backpack")
  65. local character = player.Character
  66.  
  67. if backpack then
  68. local key = backpack:FindFirstChild("ChestKey")
  69.  
  70. if key and key:IsA("Tool") then
  71. return true
  72. end
  73. end
  74.  
  75. if character then
  76. local key = character:FindFirstChild("ChestKey")
  77.  
  78. if key and key:IsA("Tool") then
  79. return true
  80. end
  81. end
  82.  
  83. return false
  84. end
  85.  
  86. -- Открытие сундука
  87. local function OpenChest()
  88. if Opened then
  89. return
  90. end
  91.  
  92. Opened = true
  93.  
  94. local tween = TweenService:Create(
  95. Hinge,
  96. TweenInfo.new(
  97. Config.OpenAnimation.Duration,
  98. Config.OpenAnimation.EasingStyle,
  99. Config.OpenAnimation.EasingDirection
  100. ),
  101. {
  102. CFrame = Hinge.CFrame
  103. * CFrame.Angles(
  104. math.rad(Config.OpenAnimation.Angle),
  105. 0,
  106. 0
  107. )
  108. }
  109. )
  110.  
  111. PlaySound(OpenSound)
  112. tween:Play()
  113. tween.Completed:Wait()
  114. end
  115.  
  116. -- Закрытие сундука
  117. local function CloseChest()
  118. if not Opened then
  119. return
  120. end
  121.  
  122. Opened = false
  123.  
  124. local tween = TweenService:Create(
  125. Hinge,
  126. TweenInfo.new(
  127. Config.CloseAnimation.Duration,
  128. Config.CloseAnimation.EasingStyle,
  129. Config.CloseAnimation.EasingDirection
  130. ),
  131. {
  132. CFrame = Hinge.CFrame
  133. * CFrame.Angles(
  134. math.rad(Config.CloseAnimation.Angle),
  135. 0,
  136. 0
  137. )
  138. }
  139. )
  140.  
  141. PlaySound(CloseSound)
  142. tween:Play()
  143. tween.Completed:Wait()
  144. end
  145.  
  146. -- Нажатие E возле сундука
  147. Prompt.Triggered:Connect(function(player)
  148. if Busy then
  149. return
  150. end
  151.  
  152. -- Для открытия нужен ключ.
  153. -- Закрывать уже открытый сундук можно без ключа.
  154. if not Opened and not PlayerHasKey(player) then
  155. warn(player.Name .. " попытался открыть сундук без ключа")
  156. return
  157. end
  158.  
  159. Busy = true
  160. Prompt.Enabled = false
  161.  
  162. if not Opened then
  163. OpenChest()
  164.  
  165. Prompt.MaxActivationDistance =
  166. Config.ProximityPrompt.OpenedDistance
  167. else
  168. CloseChest()
  169.  
  170. Prompt.MaxActivationDistance =
  171. Config.ProximityPrompt.DefaultDistance
  172. end
  173.  
  174. Prompt.Enabled = true
  175. Busy = false
  176. end)
  177.  
Advertisement
Add Comment
Please, Sign In to add comment