Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TweenService = game:GetService("TweenService")
- local DebrisService = game:GetService("Debris")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local ContentProviderService = game:GetService("ContentProvider")
- local random = Random.new()
- local MainPuzzle = script.Parent.Parent
- local Set = MainPuzzle.Set
- local PuzzleEffects = MainPuzzle.PuzzleEffects
- local RootPart = Set.RootPart
- local CopyHand1 = Set.CopyHand
- local CopyHand2 = Set.CopyHand2
- local CopyHand3 = Set.CopyHand3
- local RotateableHand1 = Set.RotateableHand
- local RotateableHand2 = Set.RotateableHand2
- local RotateableHand3 = Set.RotateableHand3
- local FinishedFlickering = script.FinishedFlickering
- local HandsTable = {CopyHand1, CopyHand2, CopyHand3, RotateableHand1, RotateableHand2, RotateableHand3}
- local SidesTable = {["A"] = Vector3.new(0, 0, 0), ["B"] = Vector3.new(0, 90, 0), ["C"] = Vector3.new(0, 180, 0), ["D"] = Vector3.new(0, -90, 0)}
- local SidesWithoutVectors = {"A", "B", "C", "D"}
- local LinkHands : {BasePart} = {[CopyHand1] = RotateableHand1, [CopyHand2] = RotateableHand2, [CopyHand3] = RotateableHand3}
- function setRandomSide(hand: BasePart)
- local randomSide : string = SidesWithoutVectors[math.random(1, #SidesWithoutVectors)]
- local connectedHand : BasePart = LinkHands[hand]
- if randomSide ~= connectedHand:GetAttribute("Side") then
- local rotation : Vector3 = SidesTable[randomSide]
- hand.CFrame *= CFrame.Angles(0, math.rad(rotation.Y), 0)
- hand:SetAttribute("Side", randomSide)
- hand:SetAttribute("Rotation", rotation)
- else
- setRandomSide(hand)
- end
- end
- function checkInputs()
- if CopyHand1:GetAttribute("Side") == RotateableHand1:GetAttribute("Side") then
- if CopyHand2:GetAttribute("Side") == RotateableHand2:GetAttribute("Side") then
- if CopyHand3:GetAttribute("Side") == RotateableHand3:GetAttribute("Side") then
- return true
- else
- return false
- end
- else
- return false
- end
- else
- return false
- end
- end
- function completePuzzle()
- task.wait(2.3)
- local areLightsOff = false
- local rumbleSound = Instance.new("Sound")
- rumbleSound.Parent = RootPart
- rumbleSound.Volume = 0.7
- rumbleSound.Name = "LightsOffSound"
- rumbleSound.SoundId = "rbxassetid://9113223789"
- rumbleSound.PlaybackSpeed = 1.2
- rumbleSound:Play()
- ContentProviderService:PreloadAsync({rumbleSound})
- DebrisService:AddItem(rumbleSound, rumbleSound.TimeLength + 0.2)
- ReplicatedStorage.CameraShake:FireAllClients(0.15, 2.5)
- task.spawn(function()
- local rate = 0.1
- local cancel = false
- FinishedFlickering.Event:Connect(function()
- cancel = true
- end)
- while task.wait(.02) do
- rate += random:NextNumber(0.025, 0.055)
- for _, part in pairs(Set:GetChildren()) do
- if string.find(part.Name, "Hand") then
- part.CFrame *= CFrame.Angles(0, math.rad(rate), 0)
- end
- end
- if cancel then
- break
- end
- end
- end)
- for _, light in pairs(PuzzleEffects:GetChildren()) do
- task.spawn(function()
- for i = 1, 59 do
- local flickerSound = Instance.new("Sound")
- flickerSound.Parent = light
- flickerSound.Name = "FlickerSound"
- flickerSound.Volume = 0.3
- flickerSound.PlaybackSpeed = random:NextNumber(0.85, 1.05)
- local flickerIds = {"rbxasset://4398878054", "rbxassetid://4288784832"}
- flickerSound.SoundId = flickerIds[math.random(1, #flickerIds)]
- ContentProviderService:PreloadAsync({flickerSound})
- flickerSound:Play()
- DebrisService:AddItem(flickerSound, flickerSound.TimeLength + 0.2)
- if light.Color == Color3.new(0, 0, 0) then
- light.Color = Color3.new(1, 1, 1)
- else
- light.Color = Color3.new(0, 0, 0)
- end
- for _, instance in pairs(light:GetDescendants()) do
- if instance:IsA("Light") or instance:IsA("ParticleEmitter") then
- instance.Enabled = not instance.Enabled
- end
- end
- task.wait(random:NextNumber(0.1, 0.175))
- end
- FinishedFlickering:Fire()
- return
- end)
- end
- FinishedFlickering.Event:Connect(function()
- if not areLightsOff then
- areLightsOff = true
- local lightsOffSound = Instance.new("Sound")
- lightsOffSound.Parent = RootPart
- lightsOffSound.Volume = 2
- lightsOffSound.Name = "LightsOffSound"
- lightsOffSound.SoundId = "rbxassetid://3466798390"
- lightsOffSound:Play()
- ContentProviderService:PreloadAsync({lightsOffSound})
- DebrisService:AddItem(lightsOffSound, lightsOffSound.TimeLength + 0.2)
- end
- end)
- end
- function lockAllInputs()
- for _, instance in pairs(Set:GetDescendants()) do
- if instance:IsA("ProximityPrompt") then
- instance:Destroy()
- end
- end
- end
- function setNextSide(hand : BasePart)
- local currentSide = hand:GetAttribute("Side")
- local nextSideIndex = table.find(SidesWithoutVectors, currentSide) + 1
- if nextSideIndex > 4 then
- nextSideIndex = 1
- end
- local newSide = SidesWithoutVectors[nextSideIndex]
- local sideRotation = SidesTable[newSide]
- local rotationInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
- local newCframe = hand.CFrame * CFrame.Angles(0, math.rad(90), 0)
- local properties = {CFrame = newCframe}
- local slidingRockSound = Instance.new("Sound")
- slidingRockSound.Parent = hand
- slidingRockSound.SoundId = "rbxassetid://9118657619"
- slidingRockSound.Volume = 0.75
- slidingRockSound.PlaybackSpeed = 1.1
- TweenService:Create(hand, rotationInfo, properties):Play()
- slidingRockSound:Play()
- DebrisService:AddItem(slidingRockSound, slidingRockSound.TimeLength + 0.5)
- task.wait(3)
- hand:SetAttribute("Side", newSide)
- hand:SetAttribute("Rotation", sideRotation)
- end
- function initiatePuzzle()
- for _, hand in pairs(HandsTable) do
- if string.find(hand.Name, "Rotate") then
- local proximityPrompt = Instance.new("ProximityPrompt")
- proximityPrompt.Parent = hand:FindFirstChild("Mesh")
- proximityPrompt.RequiresLineOfSight = false
- proximityPrompt.ActionText = "Rotate"
- local onCooldown = false
- proximityPrompt.Triggered:Connect(function(player)
- if not onCooldown then
- onCooldown = true
- proximityPrompt.Enabled = false
- setNextSide(hand)
- proximityPrompt.Enabled = true
- onCooldown = false
- local completed = checkInputs()
- if completed then
- lockAllInputs()
- ReplicatedStorage.CompletedPuzzle:Fire()
- local completedSound = Instance.new("Sound")
- completedSound.Parent = RootPart
- completedSound.SoundId = "rbxassetid://131940514294095"
- completedSound.Volume = 3
- completedSound.PlaybackSpeed = 0.8
- completedSound:Play()
- DebrisService:AddItem(completedSound, completedSound.TimeLength + 0.5)
- completePuzzle()
- end
- end
- end)
- elseif string.find(hand.Name, "Copy") then
- setRandomSide(hand)
- end
- end
- end
- initiatePuzzle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement