flashlight esp
Key RequiredUniversal

flashlight esp

Universal Scripttroll13168troll13168 245 views 2.6K executesUpdated Jun 20, 2026
Unrated
00
Lua Script•364 lines (9104 chars)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local player = Players.LocalPlayer
local flashlight

-- 💾 SETTINGS
local settings = {
	color = Color3.fromRGB(255,255,255),
	range = 150,
	angle = 50,
	brightness = 2,
	enabled = false,
	keybind = Enum.KeyCode.F
}

local waitingForKey = false

-- CLEAN UI
if getgenv().FlashlightUI then
	getgenv().FlashlightUI:Destroy()
end

---------------------------------------------------
-- CHARACTER FLASHLIGHT
---------------------------------------------------
local function setupCharacter(character)
	local head = character:WaitForChild("Head")

	for _, v in ipairs(head:GetChildren()) do
		if v:IsA("SpotLight") then
			v:Destroy()
		end
	end

	flashlight = Instance.new("SpotLight")
	flashlight.Parent = head
	flashlight.Color = settings.color
	flashlight.Range = settings.range
	flashlight.Angle = settings.angle
	flashlight.Brightness = settings.brightness
	flashlight.Enabled = settings.enabled
end

if player.Character then
	setupCharacter(player.Character)
end

player.CharacterAdded:Connect(setupCharacter)

---------------------------------------------------
-- GLOBAL COLOR APPLY (FIXED)
---------------------------------------------------
local function applyGlobalColor(newColor)
	settings.color = newColor

	-- current flashlight
	if flashlight then
		flashlight.Color = newColor
	end

	-- future respawns
	player.CharacterAdded:Connect(function(char)
		task.wait(0.1)
		local head = char:WaitForChild("Head")
		local light = head:FindFirstChildOfClass("SpotLight")
		if light then
			light.Color = settings.color
		end
	end)

	-- stage + highlights
	for _, data in pairs(stageCache or {}) do
		if data.light then
			data.light.Color = newColor
		end
		if data.highlight then
			data.highlight.FillColor = newColor
		end
	end
end

---------------------------------------------------
-- GUI
---------------------------------------------------
local gui = Instance.new("ScreenGui")
gui.Name = "FlashlightGUI"
gui.ResetOnSpawn = false
gui.Parent = player:WaitForChild("PlayerGui")

getgenv().FlashlightUI = gui

local settingsButton = Instance.new("TextButton")
settingsButton.Size = UDim2.new(0,120,0,40)
settingsButton.Position = UDim2.new(0,20,0.2,0)
settingsButton.Text = "Settings"
settingsButton.Parent = gui

local container = Instance.new("Frame")
container.Size = UDim2.new(0,240,0,600)
container.Position = UDim2.new(0,20,0.3,0)
container.BackgroundColor3 = Color3.fromRGB(30,30,30)
container.Visible = false
container.Parent = gui

local openPos = UDim2.new(0,20,0.3,0)
local closedPos = UDim2.new(-0.6,0,0.3,0)

local function openMenu()
	container.Visible = true
	container.Position = closedPos
	TweenService:Create(container, TweenInfo.new(0.25), {Position = openPos}):Play()
end

local function closeMenu()
	local t = TweenService:Create(container, TweenInfo.new(0.25), {Position = closedPos})
	t:Play()
	t.Completed:Connect(function()
		container.Visible = false
	end)
end

local menuOpen = false
settingsButton.MouseButton1Click:Connect(function()
	menuOpen = not menuOpen
	if menuOpen then openMenu() else closeMenu() end
end)

---------------------------------------------------
-- DRAG SYSTEM
---------------------------------------------------
local function makeDrag(frame)
	local dragging = false
	local start, pos

	frame.InputBegan:Connect(function(i)
		if i.UserInputType == Enum.UserInputType.MouseButton1
		or i.UserInputType == Enum.UserInputType.Touch then

			dragging = true
			start = i.Position
			pos = frame.Position

			i.Changed:Connect(function()
				if i.UserInputState == Enum.UserInputState.End then
					dragging = false
				end
			end)
		end
	end)

	UserInputService.InputEnded:Connect(function(i)
		if i.UserInputType == Enum.UserInputType.MouseButton1
		or i.UserInputType == Enum.UserInputType.Touch then
			dragging = false
		end
	end)

	UserInputService.InputChanged:Connect(function(i)
		if dragging and i.UserInputType == Enum.UserInputType.MouseMovement then
			local d = i.Position - start
			frame.Position = UDim2.new(
				pos.X.Scale, pos.X.Offset + d.X,
				pos.Y.Scale, pos.Y.Offset + d.Y
			)
		end
	end)
end

makeDrag(settingsButton)
makeDrag(container)

---------------------------------------------------
-- UI HELPERS
---------------------------------------------------
local function box(t,y)
	local b = Instance.new("TextBox")
	b.Size = UDim2.new(1,-10,0,30)
	b.Position = UDim2.new(0,5,0,y)
	b.PlaceholderText = t
	b.ClearTextOnFocus = false
	b.Parent = container
	return b
end

local function btn(t,y)
	local b = Instance.new("TextButton")
	b.Size = UDim2.new(1,-10,0,35)
	b.Position = UDim2.new(0,5,0,y)
	b.Text = t
	b.Parent = container
	return b
end

---------------------------------------------------
-- UI LAYOUT (FIXED)
---------------------------------------------------
local toggleBtn = btn("Flashlight OFF", 10)

local colorBox = box("R,G,B", 55)
local applyColor = btn("Apply Color", 85)

local rangeBox = box("Range", 130)
local applyRange = btn("Apply Range", 160)

local angleBox = box("Angle", 205)
local applyAngle = btn("Apply Angle", 235)

local brightnessBox = box("Brightness", 280)
local applyBrightness = btn("Apply Brightness", 310)

local keybindBtn = btn("Keybind: F", 355)

-- extra controls
local brightnessApplyBox = box("Brightness (e.g. 3)", 400)
local brightnessApplyBtn = btn("Apply Brightness Value", 430)

local colorApplyBox = box("Color (255,255,255)", 475)
local colorApplyBtn = btn("Apply Color", 505)

local targetBox = box("Player Name (Stage)", 550)
local stageBtn = btn("Toggle Stage Light", 580)

---------------------------------------------------
-- STAGE SYSTEM
---------------------------------------------------
local stageCache = {}

local function enableStage(plr)
	local char = plr.Character
	if not char then return end

	local head = char:FindFirstChild("Head")
	if not head then return end

	local light = Instance.new("SpotLight")
	light.Parent = head
	light.Face = Enum.NormalId.Top
	light.Angle = 120
	light.Range = 35
	light.Brightness = 4
	light.Color = settings.color

	local highlight = Instance.new("Highlight")
	highlight.Parent = char
	highlight.FillColor = settings.color

	stageCache[plr] = {light = light, highlight = highlight}
end

local function disableStage(plr)
	local data = stageCache[plr]
	if not data then return end

	if data.light then data.light:Destroy() end
	if data.highlight then data.highlight:Destroy() end

	stageCache[plr] = nil
end

stageBtn.MouseButton1Click:Connect(function()
	local name = targetBox.Text
	local target = Players:FindFirstChild(name)

	if not target then return end

	if stageCache[target] then
		disableStage(target)
	else
		enableStage(target)
	end
end)

---------------------------------------------------
-- FLASHLIGHT LOGIC
---------------------------------------------------
local function toggleFlashlight()
	if flashlight then
		settings.enabled = not settings.enabled
		flashlight.Enabled = settings.enabled
		toggleBtn.Text = settings.enabled and "Flashlight ON" or "OFF"
	end
end

UserInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if waitingForKey then
		if input.KeyCode ~= Enum.KeyCode.Unknown then
			settings.keybind = input.KeyCode
			waitingForKey = false
			keybindBtn.Text = "Keybind: " .. settings.keybind.Name
		end
		return
	end

	if input.KeyCode == settings.keybind then
		toggleFlashlight()
	end
end)

keybindBtn.MouseButton1Click:Connect(function()
	waitingForKey = true
	keybindBtn.Text = "Press a key..."
end)

toggleBtn.MouseButton1Click:Connect(toggleFlashlight)

---------------------------------------------------
-- APPLY SETTINGS
---------------------------------------------------
applyColor.MouseButton1Click:Connect(function()
	local r,g,b = colorBox.Text:match("(%d+),(%d+),(%d+)")
	r,g,b = tonumber(r),tonumber(g),tonumber(b)

	if r and g and b then
		applyGlobalColor(Color3.fromRGB(r,g,b))
	end
end)

applyRange.MouseButton1Click:Connect(function()
	local v = tonumber(rangeBox.Text)
	if v then
		settings.range = v
		if flashlight then flashlight.Range = v end
	end
end)

applyAngle.MouseButton1Click:Connect(function()
	local v = tonumber(angleBox.Text)
	if v then
		settings.angle = v
		if flashlight then flashlight.Angle = v end
	end
end)

applyBrightness.MouseButton1Click:Connect(function()
	local v = tonumber(brightnessBox.Text)
	if v then
		settings.brightness = v
		if flashlight then flashlight.Brightness = v end
	end
end)

---------------------------------------------------
-- EXTRA FEATURES
---------------------------------------------------
brightnessApplyBtn.MouseButton1Click:Connect(function()
	local v = tonumber(brightnessApplyBox.Text)
	if v then
		settings.brightness = v
		if flashlight then flashlight.Brightness = v end
	end
end)

colorApplyBtn.MouseButton1Click:Connect(function()
	local r,g,b = colorApplyBox.Text:match("(%d+),(%d+),(%d+)")
	r,g,b = tonumber(r), tonumber(g), tonumber(b)

	if r and g and b then
		applyGlobalColor(Color3.fromRGB(r,g,b))
	end
end)

Features & Information

flashlight made with ai
#ai#chatgpt#chat gpt#flashlight#esp

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts