Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Flashlight Script
- -- Made by spirit_awoken
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local TweenService = game:GetService("TweenService")
- local player = Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
- -- Create flashlight
- local flashlight = Instance.new("SpotLight")
- flashlight.Angle = 65
- flashlight.Range = 50
- flashlight.Brightness = 0
- flashlight.Parent = humanoidRootPart
- -- Create sound effects
- local onSound = Instance.new("Sound")
- onSound.SoundId = "rbxassetid://9114481260" -- Replace with on sound ID
- onSound.Volume = 1.2 -- Adjust volume as needed
- onSound.MaxDistance = 50 -- Adjust max distance as needed
- onSound.Parent = humanoidRootPart
- local offSound = Instance.new("Sound")
- offSound.SoundId = "rbxassetid://9114481260" -- Replace with off sound ID
- offSound.Volume = 1.2 -- Adjust volume as needed
- offSound.MaxDistance = 50 -- Adjust max distance as needed
- offSound.Parent = humanoidRootPart
- local isOn = false
- local cooldown = false
- local function toggleFlashlight()
- if cooldown then return end
- cooldown = true
- if isOn then
- -- Turn off
- offSound:Play()
- local tweenOff = TweenService:Create(flashlight, TweenInfo.new(0.2), {Brightness = 0})
- tweenOff:Play()
- isOn = false
- else
- -- Turn on
- onSound:Play()
- local tweenOn = TweenService:Create(flashlight, TweenInfo.new(0.2), {Brightness = 2})
- tweenOn:Play()
- isOn = true
- end
- wait(1) -- 1 second cooldown
- cooldown = false
- end
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if not gameProcessed and input.KeyCode == Enum.KeyCode.F then
- toggleFlashlight()
- end
- end)
- -- Tips:
- -- 1. Adjust flashlight properties (Angle, Range, Brightness) to customize the light
- -- 2. Replace "SOUND_ID_HERE" with actual Roblox sound asset IDs
- -- 3. Modify Volume and MaxDistance of sounds to fit your game's needs
- -- 4. Change the cooldown time by adjusting the wait(1) value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement