Advertisement
SiegedTrooper

ROBLOX: Flickering Light Tutorial

Aug 5th, 2018
1,199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. --TimeSensor--
  2. TurnOn = 19
  3. TurnOff = 7
  4. On = false
  5. while wait(10) do
  6.     if game.Lighting.ClockTime >= TurnOn then
  7.         if not On then
  8.             On = true
  9.             script.Parent.Flicker.On.Value = true
  10.         end
  11.     elseif game.Lighting.ClockTime >= TurnOff then
  12.         if On then
  13.             On = false
  14.             script.Parent.Flicker.On.Value = false
  15.         end
  16.     end
  17. end
  18.  
  19. --Flickering--
  20.  
  21. -- Anything parented to this script's parent will be lit up!
  22.  
  23. MaxFlickerWait = 30
  24. MinFlickerWait = 10
  25. Allow = false
  26. function Change(Mode)
  27.     for _,i in pairs (script.Parent:GetChildren()) do
  28.         if i:IsA("BasePart") then
  29.             if Mode then
  30.                 i.Material = "Neon"
  31.             else
  32.                 i.Material = "SmoothPlastic"
  33.             end
  34.         elseif i:IsA("Model") then
  35.             for _,i in pairs (i:GetChildren()) do
  36.                 if Mode then
  37.                     i.Material = "Neon"
  38.                 else
  39.                     i.Material = "SmoothPlastic"
  40.                 end
  41.             end
  42.         end
  43.     end
  44. end
  45. script.On.Changed:connect(function()
  46.     if script.On.Value then
  47.         Allow = true
  48.         Change(true)
  49.     else
  50.         Allow = false
  51.         Change(false)
  52.     end
  53. end)
  54. while wait(math.random(MinFlickerWait,MaxFlickerWait)) do
  55.     if Allow then
  56.         local function Check() if not Allow then return end end
  57.         local WaitTime = .5
  58.         Change(false)
  59.         wait(WaitTime/2); Check();
  60.         Change(true)
  61.         wait(WaitTime); Check()
  62.         Change(false)
  63.         wait(WaitTime*1.5); Check()
  64.         Change(true)
  65.         wait(WaitTime); Check()
  66.         Change(false)
  67.         wait(WaitTime/5); Check()
  68.         Change(true)
  69.         wait(WaitTime); Check()
  70.         Change(false)
  71.         wait(WaitTime/8); Check()
  72.         Change(true)
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement