I would like to make a rig walk towards a set of parts.
The issue is that they don’t move to the part itself, but to completely different locations.
I’ve used Humanoid:MoveTo() to make the rigs humanoids move and it has worked, but it still never sends them to the correct location.
Here is the full script currently:
task.wait()
local GangNeighbourhood = game:GetService("Workspace"):FindFirstChild("Map 1")
local SuburbanNeighbourhood = game:GetService("Workspace"):FindFirstChild("Map 2")
local Playground = game:GetService("Workspace"):FindFirstChild("Map 3")
local Beach = game:GetService("Workspace"):FindFirstChild("Map 4")
local Desert = game:GetService("Workspace"):FindFirstChild("Map 5")
local GNRigs = GangNeighbourhood:FindFirstChild("Map 1 Rigs"):GetChildren()
local SNRigs = SuburbanNeighbourhood:FindFirstChild("Suburban Rigs")
--local PGRigs = Playground:FindFirstChild("Rigs")
--local BHRigs = Beach:FindFirstChild("Rigs")
--local DTRigs = Desert:FindFirstChild("Rigs")
local CustomerSpawnInterval = 3
local SNCustomerWalksToPoints = SuburbanNeighbourhood:FindFirstChild("CustomerWalksTo")
local function SpawnCustomer(AvailableTrucks)
if #AvailableTrucks >= 1 then
local Customer = SNRigs:FindFirstChild("Rig"..tostring(math.random(1, #SNRigs:GetChildren())))
local CustomerClone = Customer:Clone()
CustomerClone.Parent = Customer.Parent
local RandomNumber = math.random(1, #AvailableTrucks)
local TargetTruck = AvailableTrucks[RandomNumber]
CustomerClone:FindFirstChild("TargetTruck").Value = TargetTruck
CustomerClone:MoveTo(SNCustomerWalksToPoints.Spawn.Position)
if CustomerClone:FindFirstChild("TargetTruck").Value == "Location_1" then
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop3").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Truck1").Position)
elseif CustomerClone:FindFirstChild("TargetTruck").Value == "Location_2" then
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop4").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop7").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Truck2").Position)
elseif CustomerClone:FindFirstChild("TargetTruck").Value == "Location_3" then
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop4").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop8").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Truck3").Position)
elseif CustomerClone:FindFirstChild("TargetTruck").Value == "Location_4" then
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop2").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop6").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Truck4").Position)
elseif CustomerClone:FindFirstChild("TargetTruck").Value == "Location_5" then
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop1").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Truck5").Position)
elseif CustomerClone:FindFirstChild("TargetTruck").Value == "Location_6" then
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop2").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Stop5").Position)
CustomerClone:FindFirstChild("Humanoid").MoveToFinished:Wait()
CustomerClone:FindFirstChild("Humanoid"):MoveTo(SNCustomerWalksToPoints:FindFirstChild("Truck6").Position)
end
end
end
while true do
task.wait(CustomerSpawnInterval)
--local RandomNumber = math.random(1, 100)
--if Number >= 1 and Number <= 22 then
local AvailableTrucks = {}
for i,v in pairs(SuburbanNeighbourhood:FindFirstChild("Truck_Locations"):GetChildren()) do
if v:FindFirstChild("Truck") then
table.insert(AvailableTrucks, v.Name)
continue
else
continue
end
end
SpawnCustomer(AvailableTrucks)
--end
end
Thank you for your time, please help me!