Advertisement
LOLTIKE

How to do smooth flashlight!

Mar 12th, 2024 (edited)
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | Gaming | 0 0
  1. -- first you need a flashlight part in replicatedstorage.
  2. -- if you don't then create it.
  3. -- after creating put a local script in StarterPlayer > StarterCharacterScripts, and open it, then type this script:
  4.  
  5. local Camera = workspace.CurrentCamera
  6. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  7. local RunService = game:GetService("RunService")
  8. local Flashlight = ReplicatedStorage.Flashlight
  9. local Clone = Flashlight:Clone()
  10. local TS = game:GetService("TweenService")
  11. local Sound = script.Parent:WaitForChild("Sound1") -- you need a your custom enabling/disabling flashlight sound!!! OR NOTHING WILL WORK, and you need name sound to Sound1
  12. Clone.Parent = script.Parent
  13.  
  14. local Brightness = 10 -- you can customize that number, that number will be brightness of flashlight.
  15.  
  16. local UIS = game:GetService("UserInputService")
  17.  
  18. local Mouse = game.Players.LocalPlayer:GetMouse()
  19.  
  20. UIS.InputBegan:Connect(function(Input, gpe)
  21.     if gpe then return end
  22.     if Input.KeyCode == Enum.KeyCode.F then
  23.         Clone.SurfaceLight.Enabled = not Clone.SurfaceLight.Enabled
  24.     end
  25. end)
  26.  
  27. RunService.RenderStepped:Connect(function()
  28.     if Clone then
  29.         Clone.Position = Camera.CFrame.Position
  30.         TS:Create(Clone, TweenInfo.new(0.1, Enum.EasingStyle.Quad), {CFrame = CFrame.lookAt(Clone.Position, Mouse.Hit.Position)}):Play()
  31.         if Clone.SurfaceLight.Enabled then
  32.             TS:Create(Clone.SurfaceLight, TweenInfo.new(0.1, Enum.EasingStyle.Quad), {Brightness = Brightness}):Play()
  33.             Sound:Play()
  34.         else
  35.             TS:Create(Clone.SurfaceLight, TweenInfo.new(0.1, Enum.EasingStyle.Quad), {Brightness = 0}):Play()
  36.             Sound:Play()
  37.         end
  38.     end
  39. end)
  40.  
  41. -- if something not working DM ME IN DISCORD!!! Name: noonie2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement