Check All Hidden Pencils Script
Key RequiredUniversal

Check All Hidden Pencils Script

Universal ScriptYosef_1220Yosef_1220 1.6K views 2.8K executesUpdated Aug 16, 2026
5.0/ 5(1 votes)
10100% Positive
Lua Script•274 lines (7889 chars)
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local espEnabled = false
local isMinimized = false
local activeEspObjects = {}
local renderConnection = nil
local scanTask = nil

local screenGui = Instance.new("ScreenGui")
screenGui.Name = "PencilEspGui"
screenGui.ResetOnSpawn = false
screenGui.Parent = PlayerGui

local mainFrame = Instance.new("Frame")
mainFrame.Name = "MainFrame"
mainFrame.Size = UDim2.new(0, 180, 0, 85)
mainFrame.Position = UDim2.new(0.5, -90, 0, 10)
mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 40)
mainFrame.ClipsDescendants = true
mainFrame.Parent = screenGui

local frameCorner = Instance.new("UICorner")
frameCorner.CornerRadius = UDim.new(0, 8)
frameCorner.Parent = mainFrame

local frameStroke = Instance.new("UIStroke")
frameStroke.Color = Color3.fromRGB(60, 60, 80)
frameStroke.Thickness = 2
frameStroke.Parent = mainFrame

local titleBar = Instance.new("Frame")
titleBar.Name = "TitleBar"
titleBar.Size = UDim2.new(1, 0, 0, 30)
titleBar.BackgroundColor3 = Color3.fromRGB(20, 20, 28)
titleBar.Parent = mainFrame

local titleCorner = Instance.new("UICorner")
titleCorner.CornerRadius = UDim.new(0, 8)
titleCorner.Parent = titleBar

local titleText = Instance.new("TextLabel")
titleText.Size = UDim2.new(1, -60, 1, 0)
titleText.Position = UDim2.new(0, 10, 0, 0)
titleText.BackgroundTransparency = 1
titleText.Text = "Pencil ESP"
titleText.TextColor3 = Color3.fromRGB(240, 240, 240)
titleText.Font = Enum.Font.SourceSansBold
titleText.TextSize = 14
titleText.TextXAlignment = Enum.TextXAlignment.Left
titleText.Parent = titleBar

local minimizeButton = Instance.new("TextButton")
minimizeButton.Name = "MinimizeButton"
minimizeButton.Size = UDim2.new(0, 25, 0, 25)
minimizeButton.Position = UDim2.new(1, -55, 0, 2.5)
minimizeButton.BackgroundTransparency = 1
minimizeButton.Text = "-"
minimizeButton.TextColor3 = Color3.fromRGB(200, 200, 200)
minimizeButton.Font = Enum.Font.SourceSansBold
minimizeButton.TextSize = 18
minimizeButton.Parent = titleBar

local closeButton = Instance.new("TextButton")
closeButton.Name = "CloseButton"
closeButton.Size = UDim2.new(0, 25, 0, 25)
closeButton.Position = UDim2.new(1, -28, 0, 2.5)
closeButton.BackgroundTransparency = 1
closeButton.Text = "×"
closeButton.TextColor3 = Color3.fromRGB(255, 80, 80)
closeButton.Font = Enum.Font.SourceSansBold
closeButton.TextSize = 18
closeButton.Parent = titleBar

local toggleButton = Instance.new("TextButton")
toggleButton.Name = "PencilEspButton"
toggleButton.Size = UDim2.new(1, -16, 0, 40)
toggleButton.Position = UDim2.new(0, 8, 0, 36)
toggleButton.BackgroundColor3 = Color3.fromRGB(45, 45, 60)
toggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
toggleButton.Text = "ESP: OFF"
toggleButton.Font = Enum.Font.SourceSansBold
toggleButton.TextSize = 15
toggleButton.Parent = mainFrame

local btnCorner = Instance.new("UICorner")
btnCorner.CornerRadius = UDim.new(0, 6)
btnCorner.Parent = toggleButton

local dragging, dragInput, dragStart, startPos

local function updateInput(input)
	local delta = input.Position - dragStart
	mainFrame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end

titleBar.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		dragging = true
		dragStart = input.Position
		startPos = mainFrame.Position

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

titleBar.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
		dragInput = input
	end
end)

UserInputService.InputChanged:Connect(function(input)
	if input == dragInput and dragging then
		updateInput(input)
	end
end)

local function getTargetPosition(target)
	if target:IsA("BasePart") then
		return target.Position
	elseif target:IsA("Model") then
		if target.PrimaryPart then
			return target.PrimaryPart.Position
		else
			return target:GetBoundingBox().Position
		end
	end
	return nil
end

local function clearEsp()
	if renderConnection then
		renderConnection:Disconnect()
		renderConnection = nil
	end
	if scanTask then
		task.cancel(scanTask)
		scanTask = nil
	end

	for _, item in ipairs(activeEspObjects) do
		if item.Highlight then item.Highlight:Destroy() end
		if item.Billboard then item.Billboard:Destroy() end
	end
	activeEspObjects = {}
end

local function applyEsp(target)
	for _, item in ipairs(activeEspObjects) do
		if item.Target == target then return end
	end

	local highlight = Instance.new("Highlight")
	highlight.Name = "PencilESP_Highlight"
	highlight.FillColor = Color3.fromRGB(255, 0, 0)
	highlight.FillTransparency = 0.5
	highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
	highlight.OutlineTransparency = 0
	highlight.Adornee = target
	highlight.Parent = target

	local billboard = Instance.new("BillboardGui")
	billboard.Name = "PencilESP_Billboard"
	billboard.Size = UDim2.new(0, 180, 0, 40)
	billboard.StudsOffset = Vector3.new(0, 2.5, 0)
	billboard.AlwaysOnTop = true
	billboard.Adornee = target
	billboard.Parent = target

	local label = Instance.new("TextLabel")
	label.Size = UDim2.new(1, 0, 1, 0)
	label.BackgroundTransparency = 1
	label.TextColor3 = Color3.fromRGB(255, 255, 255)
	label.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
	label.TextStrokeTransparency = 0
	label.Font = Enum.Font.SourceSansBold
	label.TextSize = 14
	label.Text = target.Name .. "\n[ Calculating... ]"
	label.Parent = billboard

	table.insert(activeEspObjects, {
		Target = target,
		Highlight = highlight,
		Billboard = billboard,
		Label = label
	})
end

local function scanPencils()
	for _, descendant in ipairs(Workspace:GetDescendants()) do
		if string.match(descendant.Name, "Pencil$") then
			applyEsp(descendant)
		end
	end
end

local function startDistanceTracker()
	renderConnection = RunService.RenderStepped:Connect(function()
		local character = LocalPlayer.Character
		if not character then return end
		local rootPart = character:FindFirstChild("HumanoidRootPart")
		if not rootPart then return end

		local playerPos = rootPart.Position

		for i = #activeEspObjects, 1, -1 do
			local item = activeEspObjects[i]
			if item.Target and item.Target.Parent then
				local targetPos = getTargetPosition(item.Target)
				if targetPos then
					local distance = math.floor((playerPos - targetPos).Magnitude)
					item.Label.Text = string.format("%s\n[%d Studs]", item.Target.Name, distance)
				end
			else
				if item.Highlight then item.Highlight:Destroy() end
				if item.Billboard then item.Billboard:Destroy() end
				table.remove(activeEspObjects, i)
			end
		end
	end)
end

local function start1SecondLoop()
	scanTask = task.spawn(function()
		while espEnabled do
			scanPencils()
			task.wait(1)
		end
	end)
end

toggleButton.MouseButton1Click:Connect(function()
	espEnabled = not espEnabled

	if espEnabled then
		toggleButton.Text = "ESP: ON"
		toggleButton.BackgroundColor3 = Color3.fromRGB(180, 40, 40)

		scanPencils()
		startDistanceTracker()
		start1SecondLoop()
	else
		toggleButton.Text = "ESP: OFF"
		toggleButton.BackgroundColor3 = Color3.fromRGB(45, 45, 60)
		clearEsp()
	end
end)

minimizeButton.MouseButton1Click:Connect(function()
	isMinimized = not isMinimized

	if isMinimized then
		mainFrame.Size = UDim2.new(0, 180, 0, 30)
		minimizeButton.Text = "+"
	else
		mainFrame.Size = UDim2.new(0, 180, 0, 85)
		minimizeButton.Text = "-"
	end
end)

closeButton.MouseButton1Click:Connect(function()
	clearEsp()
	screenGui:Destroy()
end)

Features & Information

Check All Hidden Pencils. (When There Gonna Be New Events, I Update This Script)
#ESP

Community Comments (0)

No comments yet for this script.

More Scripts for Universal Scripts