Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TweenService = game:GetService("TweenService")
- -- Настройки сундука
- local Config = {
- OpenAnimation = {
- Duration = 0.4,
- EasingStyle = Enum.EasingStyle.Sine,
- EasingDirection = Enum.EasingDirection.Out,
- Angle = 80
- },
- CloseAnimation = {
- Duration = 0.7,
- EasingStyle = Enum.EasingStyle.Bounce,
- EasingDirection = Enum.EasingDirection.Out,
- Angle = -80
- },
- ProximityPrompt = {
- DefaultDistance = 5,
- OpenedDistance = 12
- },
- Sounds = {
- OpenSoundId = nil,
- CloseSoundId = nil
- }
- }
- -- Объекты сундука
- local Chest = script.Parent
- local Prompt = Chest.Structure.Trigger.ProximityPrompt
- local Hinge = Chest.Structure:WaitForChild("Hinge")
- local Opened = false
- local Busy = false
- -- Создание звуков, если указаны их ID
- local OpenSound
- local CloseSound
- if Config.Sounds.OpenSoundId then
- OpenSound = Instance.new("Sound")
- OpenSound.Parent = Hinge
- OpenSound.SoundId = Config.Sounds.OpenSoundId
- OpenSound.Volume = 1
- end
- if Config.Sounds.CloseSoundId then
- CloseSound = Instance.new("Sound")
- CloseSound.Parent = Hinge
- CloseSound.SoundId = Config.Sounds.CloseSoundId
- CloseSound.Volume = 1
- end
- local function PlaySound(sound)
- if sound then
- sound:Play()
- end
- end
- -- Проверяем, есть ли у игрока нужный Tool
- local function PlayerHasKey(player)
- local backpack = player:FindFirstChildOfClass("Backpack")
- local character = player.Character
- if backpack then
- local key = backpack:FindFirstChild("ChestKey")
- if key and key:IsA("Tool") then
- return true
- end
- end
- if character then
- local key = character:FindFirstChild("ChestKey")
- if key and key:IsA("Tool") then
- return true
- end
- end
- return false
- end
- -- Открытие сундука
- local function OpenChest()
- if Opened then
- return
- end
- Opened = true
- local tween = TweenService:Create(
- Hinge,
- TweenInfo.new(
- Config.OpenAnimation.Duration,
- Config.OpenAnimation.EasingStyle,
- Config.OpenAnimation.EasingDirection
- ),
- {
- CFrame = Hinge.CFrame
- * CFrame.Angles(
- math.rad(Config.OpenAnimation.Angle),
- 0,
- 0
- )
- }
- )
- PlaySound(OpenSound)
- tween:Play()
- tween.Completed:Wait()
- end
- -- Закрытие сундука
- local function CloseChest()
- if not Opened then
- return
- end
- Opened = false
- local tween = TweenService:Create(
- Hinge,
- TweenInfo.new(
- Config.CloseAnimation.Duration,
- Config.CloseAnimation.EasingStyle,
- Config.CloseAnimation.EasingDirection
- ),
- {
- CFrame = Hinge.CFrame
- * CFrame.Angles(
- math.rad(Config.CloseAnimation.Angle),
- 0,
- 0
- )
- }
- )
- PlaySound(CloseSound)
- tween:Play()
- tween.Completed:Wait()
- end
- -- Нажатие E возле сундука
- Prompt.Triggered:Connect(function(player)
- if Busy then
- return
- end
- -- Для открытия нужен ключ.
- -- Закрывать уже открытый сундук можно без ключа.
- if not Opened and not PlayerHasKey(player) then
- warn(player.Name .. " попытался открыть сундук без ключа")
- return
- end
- Busy = true
- Prompt.Enabled = false
- if not Opened then
- OpenChest()
- Prompt.MaxActivationDistance =
- Config.ProximityPrompt.OpenedDistance
- else
- CloseChest()
- Prompt.MaxActivationDistance =
- Config.ProximityPrompt.DefaultDistance
- end
- Prompt.Enabled = true
- Busy = false
- end)
Advertisement
Add Comment
Please, Sign In to add comment