Advertisement
LapisDevelopment

Flashlight Script for ROBLOX

Aug 20th, 2015
23,665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. -- Created by supersonicfan111
  2. local p=game:GetService"Players".LocalPlayer
  3. local c=p.Character
  4. local surf='SmoothNoOutlines'
  5. if not c then error'Cannot find character, please respawn, then rerun the script' end
  6.  
  7. -- Flashlight Handle
  8. local hand=Instance.new"Part"
  9. hand.BrickColor=BrickColor.DarkGray()
  10. hand.Parent=c
  11. hand.Anchored=false
  12. hand.Locked=true
  13. hand.CanCollide=false
  14. hand.FormFactor='Custom'
  15. hand.Size=Vector3.new(1,1,2)
  16. hand.TopSurface,hand.BottomSurface=surf,surf
  17.  
  18. -- Torch Effect
  19. local fe=Instance.new"Part"
  20. fe.BrickColor=BrickColor.new"Black"
  21. fe.Parent=c
  22. fe.Anchored=false
  23. fe.Locked=true
  24. fe.CanCollide=false
  25. fe.FormFactor='Custom'
  26. fe.Size=Vector3.new(.8,.8,.2)
  27. fe.TopSurface,hand.BottomSurface=surf,surf
  28.  
  29. -- Welding stuff
  30.  
  31. -- Flash to Right Arm
  32. local weld1=Instance.new"Weld"
  33. weld1.Parent=hand
  34. weld1.Part0=hand
  35. weld1.Part1=c['Right Arm']
  36. weld1.C0=CFrame.new(0, 1.5, 0)
  37.  
  38. -- Torch Effect to Flash
  39. local weld2=Instance.new"Weld"
  40. weld2.Parent=hand
  41. weld2.Part0=hand
  42. weld2.Part1=fe
  43. weld2.C0=CFrame.new(0, 0, 1)
  44.  
  45. -- Right Arm Weld
  46. local ra=Instance.new"Weld"
  47. ra.Parent=c['Torso']
  48. ra.Part0=c['Right Arm']
  49. ra.Part1=c['Torso']
  50. ra.C0=CFrame.new(-1.5,1,0)*CFrame.Angles(math.rad(180),0,0)
  51.  
  52.  
  53.  
  54. -- Flashlight Functionality
  55.  
  56. local flashlightOn = false
  57. local Battery=100
  58.  
  59. -- Handles turning the flashlight on/off
  60. p:GetMouse().Button1Down:connect(function()
  61. flashlightOn=not flashlightOn
  62. if flashlightOn then
  63. fe.BrickColor=BrickColor.new"New Yeller"
  64. light=Instance.new"SurfaceLight"
  65. light.Parent=fe
  66. light.Range=32
  67. light.Face="Back"
  68. light.Brightness=2
  69. fe.Material="Neon"
  70. else
  71. fe.BrickColor=BrickColor.new"Black"
  72. if light then light:destroy() end
  73. fe.Material="SmoothPlastic"
  74. end
  75. end)
  76.  
  77. -- Battery Modules
  78.  
  79. -- Depleting and Charging
  80. spawn(function()
  81. while wait(1) do
  82. if flashlightOn then
  83. if Battery > 0 then
  84. Battery=Battery-1
  85. end
  86. else
  87. if Battery < 100 then
  88. Battery=Battery+1
  89. end
  90. end
  91. print(Battery)
  92. end
  93. end)
  94.  
  95. -- Turning off flashlight if the battery is too low
  96. spawn(function()
  97. while wait() do
  98. if Battery <= 0 then
  99. flashlightOn=false
  100. if light then light:destroy() end
  101. fe.BrickColor=BrickColor.new"Black"
  102. fe.Material="SmoothPlastic"
  103. end
  104. end
  105. end)
  106.  
  107. local stepped = game:GetService'RunService'.RenderStepped
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement