
Key RequiredUniversal

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
-------------------------
-- CONFIG
-------------------------
local CONFIG = {
Brightness = 4,
Range = 35,
Angle = 70,
MaxBattery = 100,
DrainRate = 8, -- Battery per second
RechargeRate = 5, -- Battery per second
PCKey = Enum.KeyCode.F,
MobileButton = true
}
-------------------------
-- PLAYER
-------------------------
local player = Players.LocalPlayer
local flashlight
local battery = CONFIG.MaxBattery
local enabled = false
-------------------------
-- GUI
-------------------------
local gui = Instance.new("ScreenGui")
gui.Name = "FlashlightGui"
gui.ResetOnSpawn = false
gui.Parent = player:WaitForChild("PlayerGui")
local batteryLabel = Instance.new("TextLabel")
batteryLabel.Size = UDim2.new(0,180,0,40)
batteryLabel.Position = UDim2.new(0.5,-90,1,-60)
batteryLabel.BackgroundTransparency = .3
batteryLabel.TextScaled = true
batteryLabel.TextColor3 = Color3.new(1,1,1)
batteryLabel.BackgroundColor3 = Color3.fromRGB(25,25,25)
batteryLabel.Parent = gui
-------------------------
-- CHARACTER
-------------------------
local function setup(character)
local head = character:WaitForChild("Head")
if flashlight then
flashlight:Destroy()
end
flashlight = Instance.new("SpotLight")
flashlight.Parent = head
flashlight.Face = Enum.NormalId.Front
flashlight.Enabled = false
flashlight.Brightness = CONFIG.Brightness
flashlight.Range = CONFIG.Range
flashlight.Angle = CONFIG.Angle
end
player.CharacterAdded:Connect(setup)
if player.Character then
setup(player.Character)
end
-------------------------
-- TOGGLE
-------------------------
local function toggle()
if battery <= 0 then
return
end
enabled = not enabled
if flashlight then
flashlight.Enabled = enabled
end
end
-------------------------
-- INPUT
-------------------------
UserInputService.InputBegan:Connect(function(input,gp)
if gp then return end
if input.KeyCode == CONFIG.PCKey then
toggle()
end
end)
-------------------------
-- MOBILE BUTTON
-------------------------
if UserInputService.TouchEnabled and CONFIG.MobileButton then
ContextActionService:BindAction(
"Flashlight",
function(_,state)
if state == Enum.UserInputState.Begin then
toggle()
end
end,
true
)
ContextActionService:SetTitle("Flashlight","🔦")
ContextActionService:SetPosition("Flashlight",UDim2.new(.82,0,.75,0))
end
-------------------------
-- BATTERY LOOP
-------------------------
RunService.RenderStepped:Connect(function(dt)
if enabled then
battery -= CONFIG.DrainRate * dt
if battery <= 0 then
battery = 0
enabled = false
if flashlight then
flashlight.Enabled = false
end
end
else
battery += CONFIG.RechargeRate * dt
if battery > CONFIG.MaxBattery then
battery = CONFIG.MaxBattery
end
end
batteryLabel.Text = string.format("🔋 %.0f%%",battery)
end)No comments yet for this script.



