I can’t make rigs walk to the specific position of a part

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!

1 Like

The code is very messy, can you explain what you want it to do in words because i cant read that with the 20 else if statements.

Also you dont want to be using so many else if statements, you should organize the parts in workspace better, for example you have under a main folder sub folders for each path and have the path parts be named 1-however many parts you want

1 Like

The important part of the code is the one with the elseif statements, they make the humanoid of the chosen rig move to certain places. The problem is, it doesn’t make them move there for some reason. I apologize for the script being a bit messy, hopefully the way I explain it can make up for that.

Can you explain what the code is meant to do I’m certain I could do it without all those else if statements

2 Likes

Sure, The code is supposed to make dummies walk up to different part positions to then reach a certain Ice cream truck. It checks if players are in the area the dummy should spawn in, if so then it chooses a random dummy from 10 models and make them walk up to those part positions I mentionned earlier. I’ve tried using WalkToPoint, WalkToPart and MoveTo but none send the dummies to the exact location of the parts they should be going to. If you still don’t understand something of the code, let me know and I’d be glad to re-explain it!

1 Like

From what i get the main thing you want your code to do is to make one of 10 random dummies to follow a path to a designated point.

  1. You dont need 10 dummies, if you want the dummies to have different appearances you can use humanoid:ApplyDescription

  2. using pathfinding service would be a lot easier then what you are attempting

  3. I dont understand what “It checks if players are in the area the dummy should spawn in” is supposed to mean

2 Likes
  1. It still picks from a random dummy fine, so that’s alright

  2. That’s the recommendation I’ve gotten from someone else and I was planning on using it if the replies here didn’t work.

  3. There are 5 areas in the game, the second one is the only one with dummies currently. The player can progress through areas and it means that it checks if the amount of players in that area (area 2) is more than 0 and then it picks a dummy. But don’t worry, the main part that has the issue is fully inside of the elseif parts.

1 Like

I’ve tried pathfinding service, but that one finds the shortest path, and I want it to follow a specific one.