Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Created by HappyH0lidays2021
- -- This script will work for any ROBLOX game
- local Player = game.Players.LocalPlayer
- local Players = game:GetService("Players")
- local Camera = workspace.CurrentCamera
- local MaxDistance = 5000
- -- Creating the Button --
- local ButtonGui = Instance.new("ScreenGui", Player.PlayerGui)
- ButtonGui.Name = "_buttonGui"
- ButtonGui.ResetOnSpawn = false
- ButtonGui.Enabled = true
- ButtonGui.ZIndexBehavior = Enum.ZIndexBehavior.Global
- local Button = Instance.new("TextButton", ButtonGui)
- Button.Name = "_button-toggle"
- Button.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
- Button.BorderColor3 = Color3.fromRGB(0, 225, 0)
- Button.BorderSizePixel = 3
- Button.Position = UDim2.new(0.408, 0, 0.728, 0)
- Button.Size = UDim2.new(0.182, 0, 0.058, 0)
- Button.Text = "Toggle ESP"
- Button.Font = Enum.Font.GothamBlack
- Button.TextColor3 = Color3.new(1, 1, 1)
- Button.TextSize = 15
- Button.ZIndex = 100000
- local IsTracking = true -- Automatically set tracking to true when script is executed
- --------------------------------------------------------------------------------------------------------------
- -- Functions
- --------------------------------------------------------------------------------------------------------------
- local function EspTrack(Humanoid, IsAnNPC)
- local Root
- if Humanoid.RigType == Enum.HumanoidRigType.R15 then -- Check if the RigType of the player is R15 or R6
- if Humanoid.Parent:FindFirstChild("UpperTorso"):IsA("CharacterMesh") then
- Humanoid.Parent:FindFirstChild("UpperTorso").Name = "_UpperTorso" -- Rename the Meshes that are called "UpperTorso" to avoid the script from mistaking it as a BodyPart
- end
- Root = Humanoid.Parent:FindFirstChild("UpperTorso")
- else
- if Humanoid.Parent:FindFirstChild("Torso"):IsA("CharacterMesh") then
- Humanoid.Parent:FindFirstChild("Torso").Name = "_Torso" -- Rename the Meshes that are called "Torso" to avoid the script from mistaking it as a BodyPart
- end
- Root = Humanoid.Parent:FindFirstChild("Torso")
- end
- if Root then
- task.spawn(function()
- local TorsoEsp = Instance.new("BoxHandleAdornment", Root)
- if IsAnNPC then
- TorsoEsp.Color3 = Color3.fromRGB(0, 170, 255)
- elseif not IsAnNPC then
- TorsoEsp.Color3 = Color3.fromRGB(0,255,0)
- end
- TorsoEsp.Transparency = 0.5
- TorsoEsp.Adornee = Root.Parent.HumanoidRootPart
- TorsoEsp.AdornCullingMode = Enum.AdornCullingMode.Never
- TorsoEsp.AlwaysOnTop = true
- TorsoEsp.Size = Vector3.new(4.4,5.4,1.4)
- TorsoEsp.CFrame = TorsoEsp.CFrame - Vector3.new(0,0.5,0)
- TorsoEsp.Visible = true
- TorsoEsp.ZIndex = 5
- -- Creating the Name ESP
- local NameEsp = Instance.new("BillboardGui", Humanoid.Parent:FindFirstChild("Head"))
- NameEsp.Name = "_name-esp-gui"
- NameEsp.AlwaysOnTop = true
- NameEsp.Enabled = true
- NameEsp.LightInfluence = 0
- NameEsp.Size = UDim2.new(0, 200, 0, 15)
- NameEsp.StudsOffset = Vector3.new(0, 2.1, 0)
- local NameEspText = Instance.new("TextLabel", NameEsp)
- NameEspText.Name = "_name-esp-text"
- NameEspText.BackgroundTransparency = 1
- NameEspText.Size = UDim2.new(0, 200, 0, 15)
- NameEspText.Font = Enum.Font.SourceSansBold
- if IsAnNPC then
- NameEspText.Text = "[NPC] "..Humanoid.Parent.Name
- NameEspText.TextColor3 = Color3.fromRGB(0, 170, 255)
- elseif not IsAnNPC then
- NameEspText.Text = Humanoid.Parent.Name
- NameEspText.TextColor3 = Color3.fromRGB(0, 255, 0)
- end
- NameEspText.TextScaled = true
- NameEspText.TextStrokeTransparency = 0
- -- Creating the Distance ESP
- local DistanceEsp = Instance.new("BillboardGui", Root)
- DistanceEsp.Name = "_distance-esp-gui"
- DistanceEsp.AlwaysOnTop = true
- DistanceEsp.Enabled = true
- DistanceEsp.LightInfluence = 0
- DistanceEsp.Size = UDim2.new(0, 200, 0, 15)
- DistanceEsp.StudsOffset = Vector3.new(0, -4.3, 0)
- local NameEspDistance = Instance.new("TextLabel", DistanceEsp)
- NameEspDistance.Name = "_distance-esp-text"
- NameEspDistance.BackgroundTransparency = 1
- NameEspDistance.Size = UDim2.new(0, 200, 0, 15)
- NameEspDistance.Font = Enum.Font.SourceSansBold
- NameEspDistance.TextScaled = true
- NameEspDistance.TextStrokeTransparency = 0
- ------------------------------------------------------------------------
- while Root and IsTracking == true do -- While Root still exists and Tracking is on, run the function
- local RayCast = Ray.new(Root.Position, (Player.Character.HumanoidRootPart.Position - Root.Position).unit*100)
- local Part, Position, Normal = game.Workspace:FindPartOnRay(RayCast, Player.Character, false,true)
- local Dist = (Player.Character.HumanoidRootPart.Position - Root.Position).magnitude
- if (Dist > MaxDistance) then
- warn("Maximum Distance Reached")
- break
- end
- Part = Instance.new("Part")
- Part.Name = "_esp-track-part"
- Part.Parent = Humanoid.Parent
- Part.Anchored = true
- Part.CanCollide = false
- Part.Size = Vector3.new(0.15, 0.15, Dist)
- Part.Transparency = 1
- Part.CFrame = CFrame.new(Root.Position ,Position) * CFrame.new(0, 0, -Dist/2)
- local Highlight = Instance.new("BoxHandleAdornment", Part)
- if IsAnNPC then
- Highlight.Color3 = Color3.fromRGB(0, 170, 255)
- NameEspDistance.Text = math.round(Dist).." Studs"
- NameEspDistance.TextColor3 = Color3.fromRGB(0, 170, 255)
- elseif not IsAnNPC then
- Highlight.Color3 = Color3.fromRGB(0,255,0)
- NameEspDistance.Text = math.round(Dist).." Studs"
- NameEspDistance.TextColor3 = Color3.fromRGB(0, 255, 0)
- end
- Highlight.Transparency = 0.5
- Highlight.Adornee = Part
- Highlight.AdornCullingMode = Enum.AdornCullingMode.Never
- Highlight.AlwaysOnTop = true
- Highlight.Size = Vector3.new(0.17, 0.17, Dist)
- Highlight.Visible = true
- Highlight.ZIndex = 0
- task.wait()
- Part:Destroy()
- end
- -- Root no longer exists or Tracking was set to off
- print('Tracking ended for "'..Root.Parent.Name..'"')
- if Root then
- NameEsp:Destroy()
- DistanceEsp:Destroy()
- TorsoEsp:Destroy()
- else
- warn('Root no longer exists in the Character "'..Root.Parent.Name..'"')
- end
- end)
- end
- end
- local function EspTrackTool(Tool) -- Exactly the same function as tracking a player, but its a Tool instead
- local Root = Tool.Handle
- if Root then
- task.spawn(function()
- local NameEsp = Instance.new("BillboardGui", Root)
- NameEsp.Name = "_name-esp-gui"
- NameEsp.AlwaysOnTop = true
- NameEsp.Enabled = true
- NameEsp.LightInfluence = 0
- NameEsp.Size = UDim2.new(0, 200, 0, 15)
- NameEsp.StudsOffset = Vector3.new(0, 2.1, 0)
- local NameEspText = Instance.new("TextLabel", NameEsp)
- NameEspText.Name = "_name-esp-text"
- NameEspText.BackgroundTransparency = 1
- NameEspText.Size = UDim2.new(0, 200, 0, 15)
- NameEspText.Font = Enum.Font.SourceSansBold
- NameEspText.Text = "[TOOL] "..Root.Parent.Name
- NameEspText.TextColor3 = Color3.fromRGB(255, 0, 0)
- NameEspText.TextScaled = true
- NameEspText.TextStrokeTransparency = 0
- --
- while Root and IsTracking == true do
- local RayCast = Ray.new(Root.Position, (Player.Character.HumanoidRootPart.Position - Root.Position).unit*100)
- local Part, Position, Normal = game.Workspace:FindPartOnRay(RayCast, Player.Character, false, true)
- local Dist = (Player.Character.HumanoidRootPart.Position - Root.Position).magnitude
- if (Dist > MaxDistance) then
- warn("Maximum Distance Reached")
- break
- end
- -- Raycast Part --
- Part = Instance.new("Part")
- Part.Name = "_esp-track-part"
- Part.Parent = Root
- Part.Anchored = true
- Part.CanCollide = false
- Part.Size = Vector3.new(0.1, 0.1, Dist)
- Part.Transparency = 1
- Part.CFrame = CFrame.new(Root.Position, Position) * CFrame.new(0, 0, -Dist/2)
- local ToolEsp = Instance.new("BoxHandleAdornment", Part)
- ToolEsp.Transparency = 0.5
- ToolEsp.Adornee = Part
- ToolEsp.AdornCullingMode = Enum.AdornCullingMode.Never
- ToolEsp.AlwaysOnTop = true
- ToolEsp.Size = Vector3.new(0.17, 0.17, Dist)
- ToolEsp.Color3 = Color3.fromRGB(255, 0, 0)
- ToolEsp.Visible = true
- ToolEsp.ZIndex = 0
- task.wait()
- Part:Destroy()
- end
- -- Tool no longer exists or Tracking was set to off
- print('Tracking ended for "'..Root.Parent.Name..'"')
- if Root then
- NameEsp:Destroy()
- else
- warn("Tool no longer exists")
- end
- end)
- end
- end
- local function CheckDistance(Object, IsAnNPC)
- if Object then
- local Torso
- if Object.RigType == Enum.HumanoidRigType.R15 then
- Torso = Object.Parent:FindFirstChild("UpperTorso")
- else
- Torso = Object.Parent:FindFirstChild("Torso")
- end
- local Distance = (Player.Character.HumanoidRootPart.Position - Torso.Position).magnitude
- if Distance <= MaxDistance then -- Maximum distance of the tracker is 5000 studs by default
- EspTrack(Object, IsAnNPC)
- else
- -- Ignore the Character as it is too far from the LocalPlayer
- print(Object.Parent.Name.." is too far from the Player")
- end
- end
- end
- local MainFunction = function()
- task.spawn(function()
- while task.wait(0.1) do
- if IsTracking then -- If tracking is on, run the function
- for _, Thing in pairs(workspace:GetDescendants()) do -- Get all objects found in the workspace
- if Thing:IsA("Humanoid") and (Thing.Health > 0) and (Thing.Parent ~= Player.Character) then -- Check if object IS a Humanoid and Character is different from the LocalPlayer's Character
- if Players:GetPlayerFromCharacter(Thing.Parent) and not Thing.Parent:FindFirstChild("_esp-track-part") then
- CheckDistance(Thing, false) -- Check the distance of the Player
- elseif not Thing.Parent:FindFirstChild("_esp-track-part") then
- CheckDistance(Thing, true) -- Check the distance of the NPC
- end
- elseif Thing:IsA("Tool") then
- if Thing:FindFirstChild("Handle") then
- if not Thing.Handle:FindFirstChild("_esp-track-part") then
- EspTrackTool(Thing) -- Track the Tool
- end
- end
- end
- end
- end
- end
- end)
- end
- Button.MouseButton1Click:Connect(function()
- if IsTracking then
- -- Disable Tracking
- IsTracking = false
- Button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
- Button.BorderColor3 = Color3.fromRGB(225, 0, 0)
- else
- -- Enable Tracking
- IsTracking = true
- Button.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
- Button.BorderColor3 = Color3.fromRGB(0, 225, 0)
- end
- end)
- task.wait() -- Wait until everything is loaded
- MainFunction() -- Run the main function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement