Advertisement
Entity-Entertainment

Flashlight Roblox Script

Sep 22nd, 2024
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | Source Code | 0 0
  1. -- Flashlight Script
  2. -- Made by spirit_awoken
  3.  
  4. local Players = game:GetService("Players")
  5. local UserInputService = game:GetService("UserInputService")
  6. local TweenService = game:GetService("TweenService")
  7.  
  8. local player = Players.LocalPlayer
  9. local character = player.Character or player.CharacterAdded:Wait()
  10. local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
  11.  
  12. -- Create flashlight
  13. local flashlight = Instance.new("SpotLight")
  14. flashlight.Angle = 65
  15. flashlight.Range = 50
  16. flashlight.Brightness = 0
  17. flashlight.Parent = humanoidRootPart
  18.  
  19. -- Create sound effects
  20. local onSound = Instance.new("Sound")
  21. onSound.SoundId = "rbxassetid://9114481260" -- Replace with on sound ID
  22. onSound.Volume = 1.2 -- Adjust volume as needed
  23. onSound.MaxDistance = 50 -- Adjust max distance as needed
  24. onSound.Parent = humanoidRootPart
  25.  
  26. local offSound = Instance.new("Sound")
  27. offSound.SoundId = "rbxassetid://9114481260" -- Replace with off sound ID
  28. offSound.Volume = 1.2 -- Adjust volume as needed
  29. offSound.MaxDistance = 50 -- Adjust max distance as needed
  30. offSound.Parent = humanoidRootPart
  31.  
  32. local isOn = false
  33. local cooldown = false
  34.  
  35. local function toggleFlashlight()
  36. if cooldown then return end
  37.  
  38. cooldown = true
  39.  
  40. if isOn then
  41. -- Turn off
  42. offSound:Play()
  43. local tweenOff = TweenService:Create(flashlight, TweenInfo.new(0.2), {Brightness = 0})
  44. tweenOff:Play()
  45. isOn = false
  46. else
  47. -- Turn on
  48. onSound:Play()
  49. local tweenOn = TweenService:Create(flashlight, TweenInfo.new(0.2), {Brightness = 2})
  50. tweenOn:Play()
  51. isOn = true
  52. end
  53.  
  54. wait(1) -- 1 second cooldown
  55. cooldown = false
  56. end
  57.  
  58. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  59. if not gameProcessed and input.KeyCode == Enum.KeyCode.F then
  60. toggleFlashlight()
  61. end
  62. end)
  63.  
  64. -- Tips:
  65. -- 1. Adjust flashlight properties (Angle, Range, Brightness) to customize the light
  66. -- 2. Replace "SOUND_ID_HERE" with actual Roblox sound asset IDs
  67. -- 3. Modify Volume and MaxDistance of sounds to fit your game's needs
  68. -- 4. Change the cooldown time by adjusting the wait(1) value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement