Advertisement
DrawingJhon

Untitled

Aug 28th, 2020 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.49 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. function onDummy(dummy)
  5.     repeat wait() until dummy:findFirstChildOfClass("Humanoid")
  6.     local humanoid = dummy:findFirstChildOfClass("Humanoid")
  7.     local torso = dummy:WaitForChild("Torso")
  8.     local minDistance = math.huge
  9.     local followThing
  10.     local function follow(plr)
  11.         RunService.Heartbeat:Connect(function()
  12.             humanoid.WalkSpeed = 14
  13.             if plr.Character then
  14.                 local plrTorso = plr.Character:findFirstChild("HumanoidRootPart")
  15.                 if plrTorso then
  16.                     local distance = (plrTorso.Position - torso.Position).magnitude
  17.                     if distance < minDistance then
  18.                         followThing = plrTorso
  19.                         minDistance = distance
  20.                     end
  21.                 end
  22.             end
  23.         end)
  24.     end
  25.  
  26.     torso.Touched:Connect(function(hit)
  27.         local hum = hit.Parent:findFirstChildOfClass("Humanoid")
  28.         if hum and hum.Parent.Name ~= "Default Dummy" then
  29.             hum:TakeDamage(10)
  30.         end
  31.     end)
  32.  
  33.     for _, plr in pairs(Players:GetPlayers()) do
  34.         follow(plr)
  35.     end
  36.     Players.PlayerAdded:Connect(follow)
  37.     RunService.Heartbeat:Connect(function()
  38.         if not followThing or followThing.Parent == nil then followThing = nil minDistance = math.huge return end
  39.         humanoid:MoveTo(followThing.Position)
  40.     end)
  41. end
  42.  
  43. for i, v in pairs(workspace:GetChildren()) do
  44.     if v.Name == "Default Dummy" and v:IsA("Model") then
  45.         onDummy(v)
  46.     end
  47. end
  48.  
  49. workspace.ChildAdded:Connect(function(obj)
  50.     if obj.Name == "Default Dummy" and v:IsA("Model") then
  51.         onDummy(obj)
  52.     end
  53. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement