Advertisement
KrYn0MoRe

anti death

Apr 23rd, 2020 (edited)
1,618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.46 KB | None | 0 0
  1. local plr = owner
  2. local oldpos = CFrame.new()
  3. local rebirthing = false
  4. local started = false
  5. local connection = nil
  6. local whitelisted_parts = {'base','baseplate'}
  7.  
  8. local pdata = {
  9.     ws = 16,
  10.     hh = 0,
  11.     msa = 89,
  12.     jp = 50,
  13.     sit = false,
  14.     platformstand = false,
  15.     autorotate = true,
  16.     usejumppower = true,
  17.     autojump = true,
  18.     --breakjoints = false
  19.     --jump = false,
  20. }
  21.  
  22. function update_pdata(...)
  23.     local data = ...
  24.     pdata = data
  25. end
  26.  
  27. function wrap(f)
  28.     return spawn(f)
  29. end
  30.  
  31. function smart_add(p)
  32.     wrap(function()
  33.         for i,v in pairs(p:GetChildren()) do
  34.             v.ChildAdded:Connect(function(obj)
  35.                 if obj:IsA('Script') or obj:IsA('LocalScript') or obj:IsA('BodyForce') or obj:IsA('BodyGyro') or obj:IsA('BodyAngularVelocity') or obj:IsA('BodyPosition') or obj:IsA('BodyMover') or obj:IsA('BodyVelocity') or obj:IsA('BodyThrust') then
  36.                     obj:Destroy()
  37.                 end
  38.             end)
  39.         end
  40.     end)
  41. end
  42.  
  43. function load_pdata(char,torso,hum)
  44.     pcall(function()
  45.         hum.WalkSpeed = pdata.ws or 16;
  46.         hum.HipHeight = pdata.hh or 0;
  47.         hum.MaxSlopeAngle = pdata.msa or 89;
  48.         hum.JumpPower = pdata.jp or 50;
  49.         hum.Sit = pdata.sit or false;
  50.         hum.PlatformStand = pdata.platformstand or false;
  51.         hum.AutoRotate = pdata.autorotate or true;
  52.         hum.UseJumpPower = pdata.usejumppower or true;
  53.         hum.AutoJumpEnabled = pdata.autojump or true;
  54.         hum.BreakJointsOnDeath = false;
  55.         hum:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false);
  56.         hum:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false);
  57.         hum.MaxHealth = 1/0
  58.         hum.Health = 1/0
  59.         torso.Velocity = Vector3.new()
  60.         torso.CFrame = oldpos
  61.         local ff = char:FindFirstChildOfClass("ForceField")
  62.         if ff then
  63.             ff:Destroy()
  64.         end
  65.         local ff = Instance.new("ForceField")
  66.         ff.Visible = false
  67.         ff.Parent = char
  68.         smart_add(char)
  69.         make_barrier(torso,char,workspace)
  70.     end)
  71. end
  72.  
  73. local bid = 0
  74.  
  75. function make_barrier(root,char,p)
  76.     wrap(function()
  77.         bid += 1
  78.         local cid = bid
  79.         if connection then connection:Disconnect(); end;
  80.         local barrier = Instance.new("Part")
  81.         barrier.Name = 'barrier'
  82.         barrier.Transparency = 1
  83.         barrier.Size = Vector3.new(10,10,10)
  84.         barrier.CanCollide = false
  85.         barrier.Massless = true
  86.         barrier.Locked = true
  87.         barrier.Archivable = false
  88.         barrier.Parent = p
  89.         local weld = Instance.new("Weld")
  90.         weld.Part0 = root
  91.         weld.Part1 = barrier
  92.         weld.Parent = barrier
  93.         barrier.Touched:Connect(function(obj)
  94.             local n = obj.Name:lower()
  95.             local found = false
  96.             for i,v in pairs(whitelisted_parts) do
  97.                 if n and v == n then
  98.                     found = true;
  99.                 end;
  100.             end;
  101.             if (char and obj:IsDescendantOf(char)) or (plr.Character and obj:IsDescendantOf(plr.Character)) or not obj:FindFirstChildOfClass('TouchInterest') then
  102.                 found = true
  103.             end
  104.             if not found then
  105.                 obj:Destroy()
  106.             end
  107.         end)
  108.         local c
  109.         c = workspace.DescendantAdded:Connect(function(obj)
  110.             if cid ~= bid then
  111.                 c:Disconnect()
  112.                 return
  113.             end
  114.             if obj:IsA("Weld") then
  115.                 local p0 = obj.Part0
  116.                 local p1 = obj.Part1
  117.                 if p0 == barrier then
  118.                     if p1 ~= barrier then
  119.                         p1:Destroy()
  120.                     end
  121.                 end
  122.                 if p1 == barrier then
  123.                     if p0 ~= barrier then
  124.                         p0:Destroy()
  125.                     end
  126.                 end
  127.                 obj:Destroy()
  128.             end
  129.         end)
  130.         barrier.ChildAdded:Connect(function(obj)
  131.             task.wait()
  132.             if obj:IsA("Weld") then
  133.                 local p0 = obj.Part0
  134.                 local p1 = obj.Part1
  135.                 if p0 ~= barrier then
  136.                     p0:Destroy()
  137.                 end
  138.                 if p1 ~= barrier then
  139.                     p1:Destroy()
  140.                 end
  141.                 obj:Destroy()
  142.             end
  143.         end)
  144.         connection = p.ChildRemoved:Connect(function(obj)
  145.             if obj == barrier then
  146.                 if obj then obj:Destroy(); end;
  147.                 make_barrier(root,char,p)
  148.             end
  149.         end)
  150.     end)
  151. end
  152.  
  153. function setup()
  154.     local char = plr.Character
  155.     local torso = char:FindFirstChild("HumanoidRootPart")
  156.     local hum = char:FindFirstChildOfClass("Humanoid")
  157.     local died = false
  158.  
  159.     local function alive()
  160.         local alive = false
  161.         if char and char.Parent and (char.Parent == workspace) and torso and torso.Parent and hum and hum.Parent and hum.Health > 0 then
  162.             alive = true
  163.         end
  164.         return alive
  165.     end
  166.  
  167.     local function rebirth()
  168.         rebirthing = true
  169.         plr:LoadCharacter()
  170.         char = plr.Character
  171.         torso = char:FindFirstChild("HumanoidRootPart")
  172.         hum = char:FindFirstChildOfClass("Humanoid")
  173.         load_pdata(char,torso,hum)
  174.         rebirthing = false
  175.         setup()
  176.     end
  177.  
  178.     local BODY = {}
  179.     wrap(function()
  180.         for _, c in pairs(char:GetDescendants()) do
  181.             if c:IsA("BasePart") and c.Name ~= "Handle" then
  182.                 if c.Name ~= "RootPart" and c.Name ~= "Torso" and c.Name ~= "Head" and c.Name ~= "RightArm" and c.Name ~= "LeftArm" and c.Name ~= "RightLeg" and c.Name ~= "LeftLeg" then
  183.                     c.CustomPhysicalProperties = PhysicalProperties.new(0, 0, 0, 0, 0)
  184.                 end
  185.                 table.insert(BODY,{c,c.Parent,c.Material,c.Color,c.Transparency,c.Size,c.Name})
  186.             elseif c:IsA("JointInstance") then
  187.                 table.insert(BODY,{c,c.Parent,nil,nil,nil,nil,nil})
  188.             end
  189.         end
  190.     end)
  191.  
  192.     local function refit()
  193.         --char.Parent = workspace
  194.         for e = 1, #BODY do
  195.             wrap(function()
  196.                 if BODY[e] ~= nil then
  197.                     local STUFF = BODY[e]
  198.                     local PART = STUFF[1]
  199.                     local PARENT = STUFF[2]
  200.                     local MATERIAL = STUFF[3]
  201.                     local COLOR = STUFF[4]
  202.                     local TRANSPARENCY = STUFF[5]
  203.                     --local SIZE = STUFF[6]
  204.                     local NAME = STUFF[7]
  205.                     if PART.ClassName == "Part" and PART.Name ~= "RootPart" then
  206.                         PART.Material = MATERIAL
  207.                         PART.Transparency = TRANSPARENCY
  208.                         PART.Name = NAME
  209.                     end
  210.                     if hum and PART and PART.Parent ~= PARENT then
  211.                         wrap(function()
  212.                             hum:Destroy()
  213.                             PART.Parent = PARENT
  214.                             hum = Instance.new("Humanoid")
  215.                             hum.Parent = char
  216.                         end)
  217.                     end
  218.                 end
  219.             end)
  220.         end
  221.     end
  222.  
  223.  
  224.     --wrap(function()
  225.         while not died do
  226.             if not alive() then
  227.                 died = true
  228.             end
  229.             if not alive() and not rebirthing then
  230.                 rebirth()
  231.             end
  232.             if alive() and not rebirthing and not died then
  233.                 refit()
  234.                 local tdata = {
  235.                     --ws = hum.WalkSpeed,
  236.                     --hh = hum.HipHeight,
  237.                     --msa = hum.MaxSlopeAngle,
  238.                     --jp = hum.JumpPower,
  239.                     sit = hum.Sit,
  240.                     --platformstand = hum.PlatformStand,
  241.                     --autorotate = hum.AutoRotate,
  242.                     --usejumppower = hum.UseJumpPower,
  243.                     --autojump = hum.AutoJumpEnabled,
  244.                 }
  245.                 update_pdata(tdata)
  246.                 if char then
  247.                     plr.Character = char
  248.                 end
  249.  
  250.                 hum.MaxHealth = 1/0; hum.Health = 1/0;
  251.                 oldpos = torso.CFrame
  252.             end
  253.             if not started then
  254.                 started = true
  255.                 plr:LoadCharacter()
  256.             end
  257.             task.wait()
  258.         end
  259.     --end)
  260. end
  261.  
  262. setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement