Advertisement
jacktaylor32

Toilet Flush Script (ROBLOX)

Jan 19th, 2020 (edited)
3,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | Source Code | 0 0
  1. local interactive = script.Parent.Interactive
  2. local handle = script.Parent.Handle
  3. local flushing = false
  4. local water = script.Parent.Water
  5. local sound = water.FlushSound
  6. local seat = script.Parent.Seat
  7.  
  8. seat.ChildAdded:connect(function(obj) -- if someone sits on the seat
  9.     if obj.Name == "SeatWeld" then
  10.         local player = game.Players:GetPlayerFromCharacter(obj.Part1.Parent)
  11.         if player then
  12.             script.Parent.Water.BrickColor = BrickColor.new("Cool yellow")
  13.             script.Parent.ToiletUsed.Value = true
  14.         end
  15.     end
  16. end)
  17.  
  18. function toiletHandle() -- handling toilet handle movement
  19.     for i = 1, 5 do
  20.         interactive.CFrame = handle.CFrame * CFrame.Angles(math.pi/2, 0, math.rad(12) * i) * CFrame.new(0, -0.1, -0.1)
  21.         wait()
  22.     end
  23.     wait(1)
  24.     for i = 5, 1, -1 do
  25.         interactive.CFrame = handle.CFrame * CFrame.Angles(math.pi/2, 0, math.rad(12) * (i - 1)) * CFrame.new(0, -0.1, -0.1)
  26.         wait()
  27.     end
  28. end
  29.  
  30. interactive.ClickDetector.MouseClick:Connect(function() -- when someone clicks on the handle
  31.     if flushing == false then
  32.         flushing = true
  33.         spawn(toiletHandle)
  34.         sound:Play()
  35.         for i, v in pairs(script.Parent:GetChildren()) do
  36.             if v.Name == "WaterSwirl" then
  37.                 v.ParticleEmitter.Transparency = NumberSequence.new(0.9)
  38.                 v.ParticleEmitter.Rate = 40
  39.             end
  40.         end
  41.        
  42.         for i = 1, 4 do
  43.             water.CFrame = water.CFrame * CFrame.new(0, 0.01, 0)
  44.             wait()
  45.         end
  46.         for i = 1, 22 do
  47.             water.Mesh.Scale = water.Mesh.Scale + Vector3.new(-0.02, 0, -0.02)
  48.             water.CFrame = water.CFrame * CFrame.new(0, -0.015, 0)
  49.             wait()
  50.         end
  51.        
  52.         if script.Parent.ToiletUsed.Value == true then
  53.             water.BrickColor = BrickColor.new("Pastel yellow")
  54.         end
  55.        
  56.         wait(1)
  57.        
  58.         for i = 1, 10 do
  59.             for ii, v in pairs(script.Parent:GetChildren()) do
  60.                 if v.Name == "WaterSwirl" then
  61.                     v.ParticleEmitter.Transparency = NumberSequence.new(0.9 + (0.015 * i))
  62.                     if i == 10 then
  63.                         v.ParticleEmitter.Rate = 0
  64.                     end
  65.                 end
  66.             end
  67.             wait(0.2)
  68.         end
  69.        
  70.         script.Parent.ToiletUsed.Value = false
  71.         water.BrickColor = BrickColor.new("Fog")
  72.        
  73.         for i = 1, 66 do
  74.             water.Mesh.Scale = water.Mesh.Scale + Vector3.new(0.0066, 0, 0.0066)
  75.             water.CFrame = water.CFrame * CFrame.new(0, 0.00409, 0)
  76.             wait()
  77.         end
  78.         water.CFrame = script.Parent.WaterResetPos.CFrame
  79.         water.Mesh.Scale = Vector3.new(1,0,1)
  80.         flushing = false
  81.     end
  82. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement