Advertisement
CatGray

Farm

Jan 4th, 2024 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local tractorName = player.Name .. " Tractor"
  3. local cropName = "Crop"
  4. local autoDungeonEnabled = true
  5.  
  6. local tractor = workspace.Tractors:FindFirstChild(tractorName)
  7. local crops = workspace.Crops.DungeonCrops
  8.  
  9. local specialCaseValue = tractor:FindFirstChild("SpecialCase")
  10. if not specialCaseValue then
  11. specialCaseValue = Instance.new("BoolValue")
  12. specialCaseValue.Name = "SpecialCase"
  13. specialCaseValue.Parent = tractor
  14. print("SpecialCaseValue Initial:", specialCaseValue and specialCaseValue.Value)
  15. end
  16.  
  17. local function getTractorType(tractor)
  18. local body = tractor:FindFirstChild("Body")
  19. local specialCaseValue = tractor:FindFirstChild("SpecialCase")
  20.  
  21. if specialCaseValue and specialCaseValue:IsA("BoolValue") and specialCaseValue.Value then
  22. return 2
  23. elseif body and (body:IsA("MeshPart") or body:IsA("Part")) then
  24. return 2
  25. else
  26. return 1
  27. end
  28. end
  29.  
  30. local tractorType = getTractorType(tractor)
  31.  
  32. local function findAndMoveTractor(model, name)
  33. for _, part in ipairs(model:GetChildren()) do
  34. if part:IsA("MeshPart") and part.Name == name and part.Transparency < 1 then
  35. if autoDungeonEnabled then
  36. for _, subPart in ipairs(part:GetChildren()) do
  37. if subPart:IsA("Part") or subPart:IsA("MeshPart") then
  38. subPart.CanCollide = false
  39. end
  40. end
  41.  
  42. local currentHeight = tractor.PrimaryPart.Position.Y
  43. local distance = (tractor.PrimaryPart.Position - part.Position).Magnitude
  44. local partHeight = part.Position.Y
  45. local newX, newZ
  46.  
  47. if tractorType == 1 or (tractorType == 2 and not specialCaseValue.Value) then
  48. newX = part.Position.X
  49. newZ = part.Position.Z + 11
  50. elseif tractorType == 2 and specialCaseValue.Value then
  51. newX = part.Position.X + 11
  52. newZ = part.Position.Z
  53. end
  54.  
  55. if distance <= 350 and math.abs(currentHeight - partHeight) <= 30 then
  56. tractor:SetPrimaryPartCFrame(CFrame.new(Vector3.new(newX, currentHeight, newZ)))
  57.  
  58. repeat
  59. wait(0.1)
  60. until part.Transparency >= 1
  61.  
  62. findAndMoveTractor(model, name)
  63. end
  64. end
  65. return
  66. elseif part:IsA("Model") or part:IsA("Folder") then
  67. findAndMoveTractor(part, name)
  68. end
  69. end
  70. end
  71.  
  72. local function onFileChanged(child, added)
  73. if autoDungeonEnabled then
  74. task.wait(0.1)
  75. findAndMoveTractor(crops, cropName)
  76. end
  77. end
  78.  
  79. crops.ChildAdded:Connect(function(child)
  80. onFileChanged(child, true)
  81. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement