Advertisement
Xmaybeu

Untitled

Apr 15th, 2025
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.88 KB | Source Code | 0 0
  1. local TweenService = game:GetService("TweenService")
  2. local DebrisService = game:GetService("Debris")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local ContentProviderService = game:GetService("ContentProvider")
  5.  
  6. local random = Random.new()
  7.  
  8. local MainPuzzle = script.Parent.Parent
  9. local Set = MainPuzzle.Set
  10. local PuzzleEffects = MainPuzzle.PuzzleEffects
  11.  
  12. local RootPart = Set.RootPart
  13. local CopyHand1 = Set.CopyHand
  14. local CopyHand2 = Set.CopyHand2
  15. local CopyHand3 = Set.CopyHand3
  16. local RotateableHand1 = Set.RotateableHand
  17. local RotateableHand2 = Set.RotateableHand2
  18. local RotateableHand3 = Set.RotateableHand3
  19.  
  20. local FinishedFlickering = script.FinishedFlickering
  21.  
  22. local HandsTable = {CopyHand1, CopyHand2, CopyHand3, RotateableHand1, RotateableHand2, RotateableHand3}
  23. 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)}
  24. local SidesWithoutVectors = {"A", "B", "C", "D"}
  25. local LinkHands : {BasePart} = {[CopyHand1] = RotateableHand1, [CopyHand2] = RotateableHand2, [CopyHand3] = RotateableHand3}
  26.  
  27. function setRandomSide(hand: BasePart)
  28.     local randomSide : string = SidesWithoutVectors[math.random(1, #SidesWithoutVectors)]
  29.     local connectedHand : BasePart = LinkHands[hand]
  30.    
  31.     if randomSide ~= connectedHand:GetAttribute("Side") then
  32.         local rotation : Vector3 = SidesTable[randomSide]
  33.        
  34.         hand.CFrame *= CFrame.Angles(0, math.rad(rotation.Y), 0)
  35.        
  36.         hand:SetAttribute("Side", randomSide)
  37.         hand:SetAttribute("Rotation", rotation)
  38.     else
  39.         setRandomSide(hand)
  40.     end
  41. end
  42.  
  43. function checkInputs()
  44.     if CopyHand1:GetAttribute("Side") == RotateableHand1:GetAttribute("Side") then
  45.         if CopyHand2:GetAttribute("Side") == RotateableHand2:GetAttribute("Side") then
  46.             if CopyHand3:GetAttribute("Side") == RotateableHand3:GetAttribute("Side") then
  47.                 return true
  48.             else
  49.                 return false
  50.             end
  51.         else
  52.             return false
  53.         end
  54.     else
  55.         return false
  56.     end
  57. end
  58.  
  59. function completePuzzle()
  60.     task.wait(2.3)
  61.    
  62.     local areLightsOff = false
  63.    
  64.     local rumbleSound = Instance.new("Sound")
  65.     rumbleSound.Parent = RootPart
  66.     rumbleSound.Volume = 0.7
  67.     rumbleSound.Name = "LightsOffSound"
  68.     rumbleSound.SoundId = "rbxassetid://9113223789"
  69.     rumbleSound.PlaybackSpeed = 1.2
  70.  
  71.     rumbleSound:Play()
  72.  
  73.     ContentProviderService:PreloadAsync({rumbleSound})
  74.  
  75.     DebrisService:AddItem(rumbleSound, rumbleSound.TimeLength + 0.2)
  76.    
  77.     ReplicatedStorage.CameraShake:FireAllClients(0.15, 2.5)
  78.    
  79.     task.spawn(function()
  80.         local rate = 0.1
  81.         local cancel = false
  82.        
  83.         FinishedFlickering.Event:Connect(function()
  84.             cancel = true
  85.         end)
  86.        
  87.         while task.wait(.02) do
  88.            
  89.             rate += random:NextNumber(0.025, 0.055)
  90.            
  91.             for _, part in pairs(Set:GetChildren()) do
  92.                 if string.find(part.Name, "Hand") then
  93.                     part.CFrame *= CFrame.Angles(0, math.rad(rate), 0)
  94.                 end
  95.             end
  96.            
  97.             if cancel then
  98.                 break
  99.             end
  100.         end
  101.     end)
  102.    
  103.     for _, light in pairs(PuzzleEffects:GetChildren()) do
  104.         task.spawn(function()
  105.             for i = 1, 59 do
  106.                 local flickerSound = Instance.new("Sound")
  107.                 flickerSound.Parent = light
  108.                 flickerSound.Name = "FlickerSound"
  109.                 flickerSound.Volume = 0.3
  110.                 flickerSound.PlaybackSpeed = random:NextNumber(0.85, 1.05)
  111.                
  112.                 local flickerIds = {"rbxasset://4398878054", "rbxassetid://4288784832"}
  113.                
  114.                 flickerSound.SoundId = flickerIds[math.random(1, #flickerIds)]
  115.                
  116.                 ContentProviderService:PreloadAsync({flickerSound})
  117.                
  118.                 flickerSound:Play()
  119.                
  120.                 DebrisService:AddItem(flickerSound, flickerSound.TimeLength + 0.2)
  121.                
  122.                 if light.Color == Color3.new(0, 0, 0) then
  123.                     light.Color = Color3.new(1, 1, 1)
  124.                 else
  125.                     light.Color = Color3.new(0, 0, 0)
  126.                 end
  127.                
  128.                 for _, instance in pairs(light:GetDescendants()) do
  129.                     if instance:IsA("Light") or instance:IsA("ParticleEmitter") then
  130.                         instance.Enabled = not instance.Enabled
  131.                     end
  132.                 end
  133.                
  134.                 task.wait(random:NextNumber(0.1, 0.175))
  135.             end
  136.            
  137.             FinishedFlickering:Fire()
  138.            
  139.             return
  140.         end)       
  141.     end
  142.    
  143.     FinishedFlickering.Event:Connect(function()
  144.         if not areLightsOff then
  145.             areLightsOff = true
  146.             local lightsOffSound = Instance.new("Sound")
  147.             lightsOffSound.Parent = RootPart
  148.             lightsOffSound.Volume = 2
  149.             lightsOffSound.Name = "LightsOffSound"
  150.             lightsOffSound.SoundId = "rbxassetid://3466798390"
  151.  
  152.             lightsOffSound:Play()
  153.  
  154.             ContentProviderService:PreloadAsync({lightsOffSound})
  155.  
  156.             DebrisService:AddItem(lightsOffSound, lightsOffSound.TimeLength + 0.2)
  157.         end
  158.     end)
  159. end
  160.  
  161. function lockAllInputs()
  162.     for _, instance in pairs(Set:GetDescendants()) do
  163.         if instance:IsA("ProximityPrompt") then
  164.             instance:Destroy()
  165.         end
  166.     end
  167. end
  168.  
  169. function setNextSide(hand : BasePart)
  170.     local currentSide = hand:GetAttribute("Side")
  171.     local nextSideIndex = table.find(SidesWithoutVectors, currentSide) + 1
  172.    
  173.     if nextSideIndex > 4 then
  174.         nextSideIndex = 1
  175.     end
  176.        
  177.     local newSide = SidesWithoutVectors[nextSideIndex]
  178.     local sideRotation = SidesTable[newSide]
  179.    
  180.     local rotationInfo = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
  181.     local newCframe = hand.CFrame * CFrame.Angles(0, math.rad(90), 0)
  182.    
  183.     local properties = {CFrame = newCframe}
  184.    
  185.     local slidingRockSound = Instance.new("Sound")
  186.     slidingRockSound.Parent = hand
  187.     slidingRockSound.SoundId = "rbxassetid://9118657619"
  188.     slidingRockSound.Volume = 0.75
  189.     slidingRockSound.PlaybackSpeed = 1.1
  190.    
  191.     TweenService:Create(hand, rotationInfo, properties):Play()
  192.     slidingRockSound:Play()
  193.    
  194.     DebrisService:AddItem(slidingRockSound, slidingRockSound.TimeLength + 0.5) 
  195.    
  196.     task.wait(3)
  197.  
  198.     hand:SetAttribute("Side", newSide)
  199.     hand:SetAttribute("Rotation", sideRotation)
  200. end
  201.  
  202. function initiatePuzzle()
  203.     for _, hand in pairs(HandsTable) do
  204.         if string.find(hand.Name, "Rotate") then
  205.             local proximityPrompt = Instance.new("ProximityPrompt")
  206.             proximityPrompt.Parent = hand:FindFirstChild("Mesh")
  207.             proximityPrompt.RequiresLineOfSight = false
  208.             proximityPrompt.ActionText = "Rotate"
  209.            
  210.             local onCooldown = false
  211.            
  212.             proximityPrompt.Triggered:Connect(function(player)
  213.                 if not onCooldown then
  214.                     onCooldown = true
  215.                     proximityPrompt.Enabled = false
  216.                    
  217.                     setNextSide(hand)
  218.                    
  219.                     proximityPrompt.Enabled = true
  220.                     onCooldown = false
  221.  
  222.                     local completed = checkInputs()
  223.  
  224.                     if completed then
  225.                         lockAllInputs()
  226.                        
  227.                         ReplicatedStorage.CompletedPuzzle:Fire()
  228.  
  229.                         local completedSound = Instance.new("Sound")
  230.                         completedSound.Parent = RootPart
  231.                         completedSound.SoundId = "rbxassetid://131940514294095"
  232.                         completedSound.Volume = 3
  233.                         completedSound.PlaybackSpeed = 0.8
  234.  
  235.                         completedSound:Play()
  236.  
  237.                         DebrisService:AddItem(completedSound, completedSound.TimeLength + 0.5)
  238.                        
  239.                         completePuzzle()
  240.                     end
  241.                 end
  242.             end)
  243.         elseif string.find(hand.Name, "Copy") then
  244.             setRandomSide(hand)
  245.         end
  246.     end
  247. end
  248.  
  249. initiatePuzzle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement