Advertisement
HowToRoblox

RainHandler

Aug 10th, 2022 (edited)
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. local particles = script:WaitForChild("RainParticles")
  2.  
  3. local underCover = false
  4.  
  5. local camera = workspace.CurrentCamera
  6.  
  7. local tweenService = game:GetService("TweenService")
  8.  
  9. local balls = {}
  10.  
  11. local lastBall = tick()
  12.  
  13.  
  14. game:GetService("RunService").RenderStepped:Connect(function()
  15.  
  16.     if not underCover then
  17.  
  18.         if workspace:FindFirstChild("RainParticles") and workspace.RainParticles ~= particles then
  19.             workspace.RainParticles:Destroy()
  20.         end
  21.  
  22.         particles.Parent = workspace
  23.  
  24.         if tick() - lastBall >= Random.new():NextNumber(0.3, 0.7) then
  25.             local ball = Instance.new("Part")
  26.  
  27.             local specialMesh = Instance.new("SpecialMesh", ball)
  28.             specialMesh.MeshType = Enum.MeshType.Sphere
  29.  
  30.             ball.Material = Enum.Material.Glass
  31.             ball.Transparency = 0.7
  32.             ball.CastShadow = false
  33.             ball.Anchored = true
  34.             ball.CanCollide = false
  35.  
  36.             local size = Random.new():NextNumber(0.1, 1.3)
  37.             ball.Size = Vector3.new(size, size, size)
  38.  
  39.             local x = Random.new():NextNumber(-40/2, 40/2)
  40.             local y = Random.new():NextNumber(-15/2, 15/2)
  41.  
  42.             local xOffset = camera.CFrame.RightVector * x
  43.             local yOffset = camera.CFrame.UpVector * y
  44.  
  45.             local zOffset = camera.CFrame.LookVector * 10
  46.  
  47.             local yTweenValue = Instance.new("NumberValue")
  48.             yTweenValue.Value = 0
  49.  
  50.             table.insert(balls, {ball, x, y, yTweenValue})
  51.  
  52.             ball.Parent = workspace
  53.  
  54.             spawn(function()
  55.  
  56.                 wait(wait(Random.new():NextNumber(0, 1)))
  57.  
  58.                 local tweenInfo = TweenInfo.new(Random.new():NextNumber(1, 3), Enum.EasingStyle.Quint, Enum.EasingDirection.In)
  59.  
  60.                 local transparencyTween = tweenService:Create(ball, tweenInfo, {Transparency = 1})
  61.                 transparencyTween:Play()
  62.  
  63.                 local dropTween = tweenService:Create(yTweenValue, tweenInfo, {Value = Random.new():NextNumber(1, 5)})
  64.                 dropTween:Play()
  65.  
  66.                 transparencyTween.Completed:Wait()
  67.                 ball:Destroy()
  68.             end)
  69.  
  70.             lastBall = tick()
  71.         end
  72.  
  73.     else
  74.  
  75.         particles.Parent = game.ReplicatedStorage
  76.     end
  77.  
  78.  
  79.     local rayParams = RaycastParams.new()
  80.     rayParams.FilterDescendantsInstances = {script.Parent, particles}
  81.  
  82.     local ray = workspace:Raycast(script.Parent.Head.Position, script.Parent.Head.Position + Vector3.new(0, 100000000, 0), rayParams)
  83.  
  84.     if ray and ray.Instance.Transparency < 1 then
  85.  
  86.         underCover = true
  87.  
  88.     else
  89.         underCover = false
  90.     end
  91.  
  92.     for i, ballInfo in pairs(balls) do
  93.  
  94.         local xOffset = camera.CFrame.RightVector * ballInfo[2]
  95.         local yOffset = camera.CFrame.UpVector * ballInfo[3]
  96.  
  97.         local zOffset = camera.CFrame.LookVector * 10
  98.  
  99.         local dropOffset = -camera.CFrame.UpVector * ballInfo[4].Value
  100.  
  101.         ballInfo[1].CFrame = camera.CFrame + xOffset + zOffset + yOffset + dropOffset
  102.  
  103.         local size = ballInfo[1].Size
  104.  
  105.         ballInfo[1].Size = Vector3.new(size.X, size.Y + ballInfo[4].Value/Random.new():NextNumber(70, 90), size.Z)
  106.     end
  107. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement