Problem with teleporting character's rootpart

I started scripting in roblox studio some months ago, and i’m programming a nextbot using roblox’s pathfinding service, to post it as a free model in the toolbox.

I want him to teleport to it’s WalkToPoint property (In humanoid) everytime he is stuck or does not move in a short period of time.

After the character’s rootpart position change, he starts to bug everytime he jumps, still moves when it’s dead, and it causes some problems with their pathfinding too.

I tried using :MoveTo() and .Position instead of .CFrame, and didn’t work, tried changing the model to another rig to check if it is some physical properties thing, and didn’t work too.

I tried to do some searching in some scripting help websites, to see if there is any problem, but everything i find is related to the rootpart’s pivot, so i decided to do this post

Here’s the script:

local bot = script.Parent.Parent
local bhrp = bot:WaitForChild("HumanoidRootPart")
local bhum = bot:WaitForChild("Humanoid")

spawn(function()
	while bot do
		local lastPosition = bhrp.CFrame.Position
		wait(1)
		if (lastPosition - bhrp.CFrame.Position).magnitude < 1 then
			local pathFind = script.Parent:WaitForChild("Pathfind")
			local pathValue = pathFind:WaitForChild("PathValue")
			if pathFind.Enabled == true and pathValue.Value == true then
				bhrp.CFrame = CFrame.new(bhum.WalkToPoint) + Vector3.new(math.random(1, 2), 2, math.random(1, 2))
			end
		end
	end
end)

And a video for the example:
what.mp4 - Google Drive (I’m using a drive link because i just can’t upload a video for this post)

Y’all know what could it be?

I tested the script (with pathfinding script) in a R6 Dummy Rig and it worked fine. When the dummy did not move for a few seconds it teleported to me.
I changed the script so that if the Bot’s health is 0, it won’t teleport to the player.

I am confused, what is the problem?

1 Like

Well, the problem with me is that everytime he teleports, something related to physics changes too, i don’t know what is this changing, but it does cause that bug

If that worked for you, i think it can be some beta testing feature enabled for me. I’m gonna try disabling some to see if that’s the problem

Setting the humanoid root part cframe sometimes can be unstable, try doing this instead:

char.PrimaryPart = char.HumanoidRootPart
char:PivotTo(cframeYouWant)
1 Like

Ok, i’m gonna try doing that to see if it’s working

try teleporting the whole nextbot model with :PivotTo(cframe)

1 Like

its better to use pivot to on the model when teleporting a character, but yeah this should work

1 Like

I’m gonna try that too, i tried doing what blueberry said, but it didn’t work

If that not work too, i’m gonna change the map lol, it can be that too

I tested with both of these scripts

Teleporting all the pivot of all parts of the model instead of just the rootpart:

local bot = script.Parent.Parent
local bhrp = bot:WaitForChild("HumanoidRootPart")
local bhum = bot:WaitForChild("Humanoid")

spawn(function()
	while bot do
		local lastPosition = bhrp.CFrame.Position
		wait(1)
		if (lastPosition - bhrp.CFrame.Position).magnitude < 1 then
			local pathFind = script.Parent:WaitForChild("Pathfind")
			local pathValue = pathFind:WaitForChild("PathValue")
			if pathFind.Enabled == true and pathValue.Value == true then
				for i, object in ipairs(bot:GetChildren()) do
					if object:IsA("BasePart") or object:IsA("MeshPart") or object:IsA("Part") then
						object:PivotTo(CFrame.new(bhum.WalkToPoint) + Vector3.new(math.random(1, 2), 2, math.random(1, 2)))
					end
				end
			end
		end
	end
end)

And teleporting the pivot of the model (bot = model):

local bot = script.Parent.Parent
local bhrp = bot:WaitForChild("HumanoidRootPart")
local bhum = bot:WaitForChild("Humanoid")

spawn(function()
	while bot do
		local lastPosition = bhrp.CFrame.Position
		wait(1)
		if (lastPosition - bhrp.CFrame.Position).magnitude < 1 then
			local pathFind = script.Parent:WaitForChild("Pathfind")
			local pathValue = pathFind:WaitForChild("PathValue")
			if pathFind.Enabled == true and pathValue.Value == true then
				bot.PrimaryPart = bhrp
				bot:PivotTo(CFrame.new(bhum.WalkToPoint) + Vector3.new(math.random(1, 2), 2, math.random(1, 2)))
			end
		end
	end
end)

i tested both of them with beta features disabled, not working :frowning:

I’m gonna try changing the map, i think it can be that

I think i got the problem. It was in my face all the time lol

It is something with MY pathfinding script, i tested him with another pathfinding script and he worked fine

Srry for creating that thread for something so obvious

Here’s he working as expected with another pathfinding: City - Roblox Studio 2022-12-12 14-12-37.mp4 - Google Drive

Now i’m gonna try to fix that problem, thanks everyone for the help


I was using :ChangeState instead of .Jump = true

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.