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)
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.
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
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
I’m gonna try changing the map, i think it can be that