RgRacks

Roblox Esp Script (Works)

May 6th, 2020
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local plr = game.Players.LocalPlayer
  2. local Char = script.Parent
  3. local UIS = game:GetService("UserInputService")
  4. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  5. local boom = Instance.new("Part")
  6.  
  7. local Key = 'E'
  8. local Debounce = true
  9.  
  10. UIS.InputBegan:Connect(function(Input, IsTyping)
  11.  if IsTyping then return end
  12.  if Input.KeyCode == Enum.KeyCode[Key] and Debounce then
  13.   Debounce = false
  14.   boom.Shape = "Ball"
  15.   local TweenService = game:GetService("TweenService")
  16.  
  17. local Plrs = game:GetService('Players')
  18. local MyPlr = Plrs.LocalPlayer
  19. repeat
  20.     wait()
  21. until MyPlr.Character ~= nil
  22. local MyChar = MyPlr.Character
  23. local MyGui = game:GetService('CoreGui')
  24. local RunS = game:GetService('RunService')
  25. local Teams = game:GetService('Teams')
  26. local C = workspace.CurrentCamera
  27. repeat
  28.     RunS.RenderStepped:wait()
  29. until C.ViewportSize.X > 0 and C.ViewportSize.Y > 0
  30.  
  31.  
  32. local Settings = {
  33.     KeyCodeToToggle = 285,
  34.     KeyCodeToScrollRight = 275,
  35.     KeyCodeToScrollLeft = 276,
  36.     ColorCodes = {
  37.         Enemy = Color3.new(1, 0, 0),
  38.         Ally = Color3.new(0, 1, 0),
  39.     },
  40.     ShowTracers = true,
  41.     TracerOptions = {
  42.         ShowEnemies = true,
  43.         ShowAllies = true,
  44.     },
  45.     ShowESP = true,
  46.     ESPOptions = {
  47.         ShowEnemies = true,
  48.         ShowAllies = true,
  49.         ShowHealth = true,
  50.         ShowName = true,
  51.         ShowDistance = true,
  52.     },
  53.     PlayerESPCrap = {},
  54.     PlayerCrap = {},
  55.     FakeCrap = {},
  56. }
  57. local CC = Settings.ColorCodes
  58. local TO = Settings.TracerOptions
  59. local ESPO = Settings.ESPOptions
  60. local PESPC = Settings.PlayerESPCrap
  61. local PC = Settings.PlayerCrap
  62.  
  63. local DONT_IGNORE = {
  64.     "Head",
  65.     "Torso",
  66.     "HumanoidRootPart",
  67.     "Left Arm",
  68.     "Right Arm",
  69.     "Left Leg",
  70.     "Right Leg",
  71. }
  72.  
  73. function CheckNameToDontIgnore(Str)
  74.     for i, v in pairs(DONT_IGNORE) do
  75.         if (Str == v) then
  76.             return true
  77.         end
  78.     end
  79.    
  80.     return false
  81. end
  82.  
  83. local Called = 0
  84. function AddShitToIgnoreList(Par)
  85.     Called = Called + 1
  86.     local Hint = Instance.new("Hint", workspace)
  87.     Hint.Text = "Called: " .. Called
  88.     -- Don't judge...
  89.    print("Preparing ESP...")
  90.    print("This could take a while...")
  91.    wait(5)
  92.    local function ScanEverything(Par)
  93.        for i, v in pairs(Par:GetChildren()) do
  94.            if not (CheckNameToDontIgnore(v.Name)) then
  95.                table.insert(Settings.FakeCrap, v)
  96.                print("Added " .. v.Name)
  97.                v.ChildAdded:connect(function(EEEE)
  98.                    ScanEverything(EEEE)
  99.                end)
  100.                ScanEverything(v)
  101.            else
  102.                ScanEverything(v)
  103.            end
  104.        end
  105.    end
  106.  
  107.    local function Scan(Par)
  108.        for i, v in pairs(Par:GetChildren()) do
  109.            if not (Plrs:FindFirstChild(v.Name)) then
  110.                table.insert(Settings.FakeCrap, v)
  111.                print("Added " .. v.Name)
  112.            else
  113.                ScanEverything(v)
  114.            end
  115.            RunS.RenderStepped:wait()
  116.        end
  117.    end
  118.    Scan(Par)
  119. end
  120.  
  121. function RecursiveGetChildren(Par)
  122.    local returnValue = {}
  123.  
  124.    local rgc
  125.    rgc = function(Par)
  126.        for i, c in next, Par:GetChildren() do
  127.            table.insert(returnValue, c)
  128.            rgc(c)
  129.        end
  130.    end
  131.  
  132.    rgc(Par)
  133.  
  134.    return returnValue
  135. end
  136.  
  137. function CheckCameraForPlrModel(Plr)
  138.    local Find = C:FindFirstChild("ESPStuff " .. Plr.Name)
  139.    if (Find) then
  140.        local Find2 = Find:FindFirstChild("Tracer Stuff")
  141.        if not (Find2) then
  142.            local T = Instance.new("Model", Find)
  143.            T.Name = "Tracer Stuff"
  144.        end
  145.        Find2 = Find:FindFirstChild("ESP Stuff")
  146.        if not (Find2) then
  147.            local T = Instance.new("Model", Find)
  148.            T.Name = "ESP Stuff"
  149.        end
  150.        return Find
  151.    end
  152.    local mod = Instance.new("Model", C)
  153.    mod.Name = "ESPStuff " .. Plr.Name
  154.    local T = Instance.new("Model", mod)
  155.    T.Name = "Tracer Stuff"
  156.    local ESP = Instance.new("Model", mod)
  157.    ESP.Name = "ESP Stuff"
  158.    return mod
  159. end
  160.  
  161. function UpdateTracerCrap(What, Plr)
  162.    if ((MyPlr.Character ~= nil and Plr.Character ~= nil) and (MyPlr.Character.PrimaryPart ~= nil and Plr.Character.PrimaryPart ~= nil)) then
  163.        if ((MyPlr.Character.PrimaryPart.Position - Plr.Character.PrimaryPart.Position).magnitude < 2000) then
  164.            local P = What.Part
  165.            P.Transparency = 0
  166.            local M = P.Mesh
  167.            if (Plr.Character == nil) then -- Only if the player character is nil do we wait for it, or updating the tracer would be laggy as fuck
  168.                repeat
  169.                    RunS.RenderStepped:wait()
  170.                until Plr.Character ~= nil
  171.            end
  172.            local R = C:ScreenPointToRay(C.ViewportSize.X / 2, C.ViewportSize.Y, 0)
  173.            local Dist = (R.Origin - (Plr.Character.PrimaryPart.Position - Vector3.new(0, 3, 0))).magnitude
  174.            P.Size = Vector3.new(0.1, 0.1, Dist)
  175.            P.CFrame = CFrame.new(R.Origin, (Plr.Character.PrimaryPart.Position - Vector3.new(0, 4.5, 0))) * CFrame.new(0, 0, -Dist / 2)
  176.            P.BrickColor = BrickColor.new(
  177.                #Teams:GetChildren() > 0 and (
  178.                    Plr.TeamColor == MyPlr.TeamColor and CC.Ally or
  179.                    Plr.TeamColor ~= MyPlr.TeamColor and CC.Enemy
  180.                ) or #Teams:GetChildren() <= 0 and CC.Enemy
  181.            )
  182.            M.Scale = Vector3.new(0.05, 0.05, P.Size.Z / Dist)
  183.        else
  184.            local P = What.Part
  185.            P.Transparency = 1
  186.        end
  187.    end
  188. end
  189.  
  190.  
  191. local Aim = 1
  192. function UpdateESPGui(HealthBar, HealthTxt, Plr, DistTxt, PlrName)
  193.    if (Plr.Character == nil) then
  194.        repeat
  195.            RunS.RenderStepped:wait()
  196.        until Plr.Character ~= nil
  197.    end
  198.    if ((Plr.Character.PrimaryPart.Position - MyPlr.Character.PrimaryPart.Position).magnitude <= 2000) then
  199.        HealthBar.Parent.Parent.Visible = true
  200.    else
  201.        HealthBar.Parent.Parent.Visible = false
  202.    end
  203.    HealthBar.Size = UDim2.new(Plr.Character.Humanoid.Health / Plr.Character.Humanoid.MaxHealth, -2, 1, -2)
  204.    HealthTxt.Text = math.floor(Plr.Character.Humanoid.Health) .. "/" .. math.floor(Plr.Character.Humanoid.MaxHealth)
  205.    local Dist = (Plr.Character.PrimaryPart.Position - MyPlr.Character.PrimaryPart.Position).magnitude
  206.    DistTxt.Text = math.floor(Dist) .. " Studs"
  207.    PlrName.TextColor3 = (
  208.        #Teams:GetChildren() > 0 and (
  209.            Plr.TeamColor == MyPlr.TeamColor and CC.Ally or
  210.            Plr.TeamColor ~= MyPlr.TeamColor and CC.Enemy
  211.        ) or #Teams:GetChildren() <= 0 and CC.Enemy
  212.    )
  213.    DistTxt.TextColor3 = (
  214.        #Teams:GetChildren() > 0 and (
  215.            Plr.TeamColor == MyPlr.TeamColor and CC.Ally or
  216.            Plr.TeamColor ~= MyPlr.TeamColor and CC.Enemy
  217.        ) or #Teams:GetChildren() <= 0 and CC.Enemy
  218.    )
  219. end
  220.  
  221. function UpdateESPCrap(What, Plr)
  222.    if ((MyPlr.Character ~= nil and Plr.Character ~= nil) and (MyPlr.Character.PrimaryPart ~= nil and Plr.Character.PrimaryPart ~= nil)) then
  223.        if ((MyPlr.Character.PrimaryPart.Position - Plr.Character.PrimaryPart.Position).magnitude < 2000) then
  224.            if (PC[Plr] ~= nil) then
  225.                local viewpoint = C.CoordinateFrame
  226.              
  227.                local PDists = {}
  228.                for i, p in next, PC[Plr] do
  229.                    table.insert(PDists, (viewpoint.p - i.Position).magnitude)
  230.                end
  231.              
  232.                local nearestDistance = math.min(unpack(PDists))
  233.                local furthestDistance = math.max(unpack(PDists))
  234.              
  235.                for i, p in next, PC[Plr] do
  236.                    local O, M, S = unpack(p)
  237.                  
  238.                  
  239.                    local Dist = (i.Position - viewpoint.p).magnitude
  240.                    local DistMult = Aim + (Dist - nearestDistance) / (furthestDistance - nearestDistance)
  241.                  
  242.                    O.Transparency = math.max(S + (i.Transparency * (1 - S)), 0.001)
  243.                  
  244.                    local unit = (i.Position - viewpoint.p).unit * DistMult
  245.                    local pos = viewpoint.p + unit
  246.                  
  247.                    local OF = CFrame.new(pos) * CFrame.Angles(i.CFrame:toEulerAnglesXYZ())
  248.                  
  249.                    O.CFrame = OF
  250.                  
  251.                    local OS = DistMult / Dist
  252.                  
  253.                    if (M == nil) then
  254.                        O.Mesh.Scale = i.Size * OS
  255.                    else
  256.                        if (M:IsA("SpecialMesh") and M.MeshType.Name == "FileMesh") or (M:IsA("SpecialMesh") == false) then
  257.                            O[M.Name].Scale = M.Scale * OS
  258.                        else
  259.                            O[M.Name].Scale = M.Scale * i.Size * OS
  260.                        end
  261.                    end
  262.                  
  263.                    O.BrickColor = BrickColor.new(
  264.                        #Teams:GetChildren() > 0 and (
  265.                            Plr.TeamColor == MyPlr.TeamColor and CC.Ally or
  266.                            Plr.TeamColor ~= MyPlr.TeamColor and CC.Enemy
  267.                        ) or #Teams:GetChildren() <= 0 and CC.Enemy
  268.                    )
  269.                end
  270.              
  271.                --print("Running")
  272.                local Mouse = MyPlr:GetMouse()
  273.                local R = Ray.new(Mouse.UnitRay.Origin, Mouse.UnitRay.Direction * 5000)
  274.                local RP = workspace:FindPartOnRayWithIgnoreList(R, Settings.FakeCrap, false, true)
  275.                if (RP ~= nil) then
  276.                    local Find = Plrs:FindFirstChild(RP.Parent.Name) or Plrs:FindFirstChild(string.sub(RP.Parent.Name, string.len("ESPStuff ") + 1))
  277.                    if ((Find and Find:IsA("Player")) and (Find ~= MyPlr and Find == Plr)) then
  278.                        Aim = 500000
  279.                        wait(3)
  280.                    else
  281.                        Aim = 1
  282.                    end
  283.                else
  284.                    Aim = 1
  285.                end
  286.            end
  287.        end
  288.    end
  289. end
  290.  
  291. function CreateESPStuff(Plr)
  292.    local ESPModel = CheckCameraForPlrModel(Plr)
  293.    PESPC[Plr] = ESPModel
  294.    if (Settings.ShowTracers) then
  295.        local T = ESPModel["Tracer Stuff"]
  296.        if not (T:FindFirstChild(Plr.Name)) then
  297.            local mod = Instance.new("Model", T)
  298.            mod.Name = Plr.Name
  299.            local P = Instance.new("Part", mod)
  300.            P.FormFactor = "Custom"
  301.            P.Material = "Neon"
  302.            P.Transparency = 0
  303.            P.Anchored = true
  304.            P.Locked = true
  305.            P.CanCollide = false
  306.            table.insert(Settings.FakeCrap, P)
  307.            local M = Instance.new("BlockMesh", P)
  308.            RunS:BindToRenderStep("TracerUpdate " .. Plr.Name, Enum.RenderPriority.Character.Value - 1, function()
  309.                UpdateTracerCrap(mod, Plr)
  310.            end)
  311.        end
  312.    end
  313.    if (Settings.ShowESP) then
  314.        local ESP = ESPModel["ESP Stuff"]
  315.        local mod = Instance.new("Model", ESP)
  316.        mod.Name = Plr.Name
  317.        repeat
  318.            RunS.RenderStepped:wait()
  319.        until Plr.Character ~= nil
  320.        for i, v in next, RecursiveGetChildren(Plr.Character) do
  321.            if (v:IsA("BasePart")) then
  322.                local O = Instance.new("Part", mod)
  323.                O.Anchored = true
  324.                O.CanCollide = false
  325.                O.FormFactor = "Custom"
  326.                O.Size = Vector3.new(1, 1, 1)
  327.                O.Name = "Fake " .. v.Name
  328.                O.Material = "SmoothPlastic"
  329.                O.TopSurface = "SmoothNoOutlines"
  330.                O.BottomSurface = "SmoothNoOutlines"
  331.                O.FrontSurface = "SmoothNoOutlines"
  332.                O.BackSurface = "SmoothNoOutlines"
  333.                O.LeftSurface = "SmoothNoOutlines"
  334.                O.RightSurface = "SmoothNoOutlines"
  335.              
  336.                local P = nil
  337.                local PMesh = nil
  338.                for ii, vv in next, RecursiveGetChildren(v) do
  339.                    if (vv:IsA("DataModelMesh")) then
  340.                        local ThisPMesh = vv:clone()
  341.                      
  342.                        local meshChanged = vv.Changed:connect(function(Prop)
  343.                            if (Prop == "MeshType" or Prop == "MeshId" or Prop == "TextureProp") then
  344.                                ThisPMesh[Prop] = vv[Prop]
  345.                            end
  346.                        end)
  347.                      
  348.                        PMesh = ThisPMesh
  349.                    elseif (vv:IsA("FaceInstance")) then
  350.                        vv:clone().Parent = O
  351.                    end
  352.                end
  353.              
  354.                if (PMesh == nil) then
  355.                    local M = Instance.new("BlockMesh", O)
  356.                else
  357.                    PMesh:clone().Parent = O
  358.                end
  359.              
  360.                if (O.Name == "Fake Head") then
  361.                    local Info = Instance.new("BillboardGui", O.Mesh)
  362.                    Info.Name = "ESPStats"
  363.                    Info.Adornee = O
  364.                    Info.Size = UDim2.new(0, 100, 0, 75)
  365.                    Info.ExtentsOffset = Vector3.new(0, 0.3, 0)
  366.                  
  367.                    local Stats = Instance.new("Frame", Info)
  368.                    Stats.BackgroundTransparency = 1
  369.                    Stats.Name = "Stats"
  370.                    Stats.Size = UDim2.new(1, 0, 1, 0)
  371.                    Stats.Visible = false
  372.                  
  373.                    local Health = Instance.new("Frame", Stats)
  374.                    Health.Name = "HealthBG"
  375.                    Health.BackgroundColor3 = Color3.new(0, 0, 0)
  376.                    Health.BorderSizePixel = 0
  377.                    Health.Position = UDim2.new(0, 0, 0, 25)
  378.                    Health.Size = UDim2.new(1, 0, 0, 25)
  379.                  
  380.                    local HealthBG = Instance.new("Frame", Health)
  381.                    HealthBG.Name = "Health"
  382.                    HealthBG.BackgroundColor3 = Color3.new(0, 1, 0)
  383.                    HealthBG.BorderSizePixel = 0
  384.                    HealthBG.Position = UDim2.new(0, 1, 0, 1)
  385.                    HealthBG.Size = UDim2.new(1, -2, 1, -2)
  386.                  
  387.                    local HealthNum = Instance.new("TextLabel", Health)
  388.                    HealthNum.Name = "HealthNum"
  389.                    HealthNum.BackgroundTransparency = 1
  390.                    HealthNum.Size = UDim2.new(1, 0, 1, 0)
  391.                    HealthNum.Font = "Legacy"
  392.                    HealthNum.FontSize = "Size8"
  393.                    HealthNum.Text = "???"
  394.                    HealthNum.TextColor3 = Color3.new(1, 0, 0)
  395.                  
  396.                    local PlrName = Instance.new("TextLabel", Stats)
  397.                    PlrName.Name = "PlrName"
  398.                    PlrName.BackgroundTransparency = 1
  399.                    PlrName.Size = UDim2.new(1, 0, 0, 25)
  400.                    PlrName.Font = "Legacy"
  401.                    PlrName.FontSize = "Size8"
  402.                    PlrName.Text = Plr.Name
  403.                    PlrName.TextColor3 = (
  404.                        #Teams:GetChildren() > 0 and (
  405.                            Plr.TeamColor == MyPlr.TeamColor and CC.Ally or
  406.                            Plr.TeamColor ~= MyPlr.TeamColor and CC.Enemy
  407.                        ) or #Teams:GetChildren() <= 0 and CC.Enemy
  408.                    )
  409.                  
  410.                    local PlrDist = PlrName:clone()
  411.                    PlrDist.Parent = PlrName.Parent
  412.                    PlrDist.Name = "Dist"
  413.                    PlrDist.Text = "???"
  414.                    PlrDist.Position = UDim2.new(0, 0, 0, 50)
  415.                    PlrDist.TextColor3 = (
  416.                        #Teams:GetChildren() > 0 and (
  417.                            Plr.TeamColor == MyPlr.TeamColor and CC.Ally or
  418.                            Plr.TeamColor ~= MyPlr.TeamColor and CC.Enemy
  419.                        ) or #Teams:GetChildren() <= 0 and CC.Enemy
  420.                    )
  421.                    RunS:BindToRenderStep("UpdateESPGui " .. Plr.Name, Enum.RenderPriority.Character.Value - 1, function()
  422.                        UpdateESPGui(HealthBG, HealthNum, Plr, PlrDist, PlrName)
  423.                    end)
  424.                end
  425.              
  426.                if (PC[Plr] == nil) then
  427.                    PC[Plr] = {}
  428.                end
  429.                PC[Plr][v] = {O, PMesh, 0}
  430.                table.insert(Settings.FakeCrap, O)
  431.                table.insert(Settings.FakeCrap, PMesh)
  432.            end
  433.        end
  434.        RunS:BindToRenderStep("UpdateESP " .. Plr.Name, Enum.RenderPriority.Character.Value - 1, function()
  435.            UpdateESPCrap(mod, Plr)
  436.        end)
  437.    end
  438. end
  439.  
  440. function RemoveESP(Plr)
  441.    RunS:UnbindFromRenderStep("UpdateESP " .. Plr.Name)
  442.    RunS:UnbindFromRenderStep("UpdateESPGui " .. Plr.Name)
  443.    local Find = C:FindFirstChild("ESPStuff " .. Plr.Name)
  444.    if (Find) then
  445.        Find = Find:FindFirstChild("ESP Stuff")
  446.        if (Find) then
  447.            Find:Destroy()
  448.        end
  449.    end
  450.    PC[Plr] = {}
  451. end
  452.  
  453. function OnCharacterAdded(Char, Plr)
  454.    RemoveESP(Plr)
  455.    CreateESPStuff(Plr)
  456.    -- Added shit to ingore list
  457. end
  458.  
  459. function OnPlayerAdded(Plr)
  460.    CreateESPStuff(Plr)
  461.    Plr.CharacterAdded:connect(function(Char)
  462.        OnCharacterAdded(Char, Plr)
  463.    end)
  464. end
  465.  
  466. function OnPlayerRemoved(Plr)
  467.    RunS:UnbindFromRenderStep("TracerUpdate " .. Plr.Name)
  468.    RunS:UnbindFromRenderStep("UpdateESP " .. Plr.Name)
  469.    RunS:UnbindFromRenderStep("UpdateESPGui " .. Plr.Name)
  470.    local Find = C:FindFirstChild("ESPStuff " .. Plr.Name)
  471.    if (Find) then
  472.        Find:Destroy()
  473.    end
  474. end
  475.  
  476. function GetCurrentPlayers()
  477.    for i, v in pairs(Plrs:GetPlayers()) do
  478.        if (v ~= MyPlr) then
  479.            CreateESPStuff(v)
  480.            v.CharacterAdded:connect(function(Char)
  481.                OnCharacterAdded(Char, v)
  482.            end)
  483.        end
  484.    end
  485. end
  486.  
  487. print("Please wait....")
  488. wait(0.5)
  489. AddShitToIgnoreList(workspace)
  490. GetCurrentPlayers()
  491. Plrs.PlayerAdded:connect(OnPlayerAdded)
  492. Plrs.PlayerRemoving:connect(OnPlayerRemoved)
  493. end
  494. end)
RAW Paste Data Copied