AI Movement persistence failing

Project

In short, I’m trying to recreate some AI that will follow the path when set.

Script

local function SetGuide(player)
	print('tracking movements for '..player.Name)

	local Place = player.Character.HumanoidRootPart.Position
--Takes the original place of the character
	
	local Steps = {}

	local function AddCO(Position,Jump)
--this small function will record the player's position relative to the starting pointit will also record whether or not the player has jumped
		table.insert(Steps,{Place-Position,Jump})
	end

	player.Character.Humanoid:GetPropertyChangedSignal('Jump'):Connect(function()	
--when the player jumps, the jump bool part of the table will be true, telling when to jump
		AddCO(player.Character.HumanoidRootPart.Position,true)
	end)

		for i = 1,100 do
			wait(.1)
			AddCO(player.Character.HumanoidRootPart.Position,false)
			if player.Character.Humanoid:GetState() == Enum.HumanoidStateType.None then
				break
			end
--Will constantly  add the position into the table. Jumping will disregard the loop and add the jump bool anyway.

		end
	return Steps
end


--this function will execute the steps given to it by a table designed by the first function
local function FollowSteps(Steps,model)
	if model then
		if Steps then
--for testing purposes, I added in a part for where every step was.
			local position = model.HumanoidRootPart.Position
			for i,v in pairs(Steps) do
				local Part = Instance.new("Part")
				Part.BrickColor = BrickColor.new("Toothpaste")
				Part.Material = 'Neon'
				Part.Size = Vector3.new(.5,.5,.5)
				Part.Position = position-v[1]
				Part.Anchored = true
				Part.CanCollide = false
				Part.Parent = workspace
			end
			assert(type(Steps) == 'table','Table required for steps, got'..type(Steps))

--This part of the script will move the character to the next position.
			for i, Data in ipairs(Steps) do
				model.Humanoid:MoveTo(position-Data[1]
				print(Data[2])
--this is supposed to print whether or not the jump bool was recorded true
				if Data[2] then
					model.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
				end
				model.Humanoid.MoveToFinished:Wait()
		
			end
		end
	end
	
end

Problem

The follow function just wont jump. It ignores the jump bool in the table. Is there something I did wrong causing this to happen? There are no errors in the output.

image
Not sure if its very clear in the picture, but the follow function has checkpoints in the air as well as multiple signals telling the NPC to jump, but it just doesn’t.

I’ve visited the wiki on ChangeState as well as MoveTo(). Just to be sure I was doing everything correctly, I visited the PathFinding wiki 3 or 4 times. I would appreciate some guidance on this. Thanks!


This was my testing script, in case it’s important

local Steps = SetGuide(game.Players:WaitForChild('ancant64'))
wait(1)
print('Data transferred')
FollowSteps(Steps,game.Workspace.Player)
1 Like

It would be useful for others if you stated whether or not there are errors in the output. Please edit your original post to clarify.

1 Like

There there 0 errors in th output, updated the post.

1 Like

Ok so what about the prints and have you tried adding more prints to see exactly which part of code is not working?

1 Like

Yes. I made it print the 2nd bool every time it reached the checkpoint. Despite printing true when necessary, it doesnt jump.

1 Like

I copied the script and pasted it into a Script in ServerScriptService and the test script as well.
Before testing I noticed that the print(Data[2]) has the print word underlined in red.
This is due to a missing right bracket in the previous statement.
I altered the test part to

local player = game.Players:WaitForChild('RamJoT')
print(player.Name)
local AP = game.Workspace:WaitForChild(player.Name)
local HRD = AP:WaitForChild("HumanoidRootPart")
local Steps = SetGuide(player)
wait(1)
print('Data transferred')
FollowSteps(Steps,AP)

On Play I got one Data transferred and 26 false lines in the output.
Does this represent your test results?

When I jump, it prints true. But other than that, yes. In addition, I have the steps executed on a dummy model.

OK, I added a dummy and ran it again doing jumps as I walked around.
The dummy did the same walk and jumps and printed true each time.
So it looks like it is working for me.
The dummy I used was a free model called Test and is a MrGrey figure.
What dummy are you using?

The dummy I was using is a free model. The one that morphs into other characters. I’m honestly puzzled as to why it wont jump for me