Advertisement
Scriptorz5

Zombie Attack AutoFarm

May 28th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. local groundDistance = 8
  2. local Player = game:GetService("Players").LocalPlayer
  3. local function getNearest()
  4. local nearest, dist = nil, 99999
  5. for _,v in pairs(game.Workspace.BossFolder:GetChildren()) do
  6. if(v:FindFirstChild("Head")~=nil)then
  7. local m =(Player.Character.Head.Position-v.Head.Position).magnitude
  8. if(m<dist)then
  9. dist = m
  10. nearest = v
  11. end
  12. end
  13. end
  14. for _,v in pairs(game.Workspace.enemies:GetChildren()) do
  15. if(v:FindFirstChild("Head")~=nil)then
  16. local m =(Player.Character.Head.Position-v.Head.Position).magnitude
  17. if(m<dist)then
  18. dist = m
  19. nearest = v
  20. end
  21. end
  22. end
  23. return nearest
  24. end
  25. _G.farm2 = true
  26. Player.Chatted:Connect(function(m)
  27. if(m==";autofarm false")then
  28. _G.farm2 = false
  29. elseif(m==";autofarm true")then
  30. _G.farm2 = true
  31. end
  32. end)
  33. _G.globalTarget = nil
  34. game:GetService("RunService").RenderStepped:Connect(function()
  35. if(_G.farm2==true)then
  36. local target = getNearest()
  37. if(target~=nil)then
  38. game:GetService("Workspace").CurrentCamera.CFrame = CFrame.new(game:GetService("Workspace").CurrentCamera.CFrame.p, target.Head.Position)
  39. Player.Character.HumanoidRootPart.CFrame = (target.HumanoidRootPart.CFrame * CFrame.new(0, groundDistance, 9))
  40. _G.globalTarget = target
  41. end
  42. end
  43. end)
  44. spawn(function()
  45. while wait() do
  46. game.Players.LocalPlayer.Character.HumanoidRootPart.Velocity = Vector3.new(0,0,0)
  47. game.Players.LocalPlayer.Character.Torso.Velocity = Vector3.new(0,0,0)
  48. end
  49. end)
  50. while wait() do
  51. if(_G.farm2==true and _G.globalTarget~=nil and _G.globalTarget:FindFirstChild("Head") and Player.Character:FindFirstChildOfClass("Tool"))then
  52. local target = _G.globalTarget
  53. game.ReplicatedStorage.Gun:FireServer({["Normal"] = Vector3.new(0, 0, 0), ["Direction"] = target.Head.Position, ["Name"] = Player.Character:FindFirstChildOfClass("Tool").Name, ["Hit"] = target.Head, ["Origin"] = target.Head.Position, ["Pos"] = target.Head.Position,})
  54. wait()
  55. end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement