HumanoidRootPart Poisiton Won't Change While Loop

I am trying to just change position of NPC. I have tried theese i will give you script below. It just change position like adding +5000 X or it turns in their position or it gives error like Vector3 expected got Cframe.

I don’t understand why i cant just move a npc with while loop.

Script:

local npc = script.Parent.Parent:WaitForChild("NPC").HumanoidRootPart.Position
local npcRoot = script.Parent.Parent:WaitForChild("NPC").HumanoidRootPart

--Tried1
while task.wait(0.2) do
npcRoot.CFrame += CFrame.new(npc.X + 1, npc.Y, npc.Z)
npcRoot:PivotTo(CFrame.new(npcRoot:GetPivot().Position) * CFrame.Angles(0, math.rad(-90), 0))
end

--Tried2
while task.wait(0.2) do
npcRoot.Position += Vector3.new(npc.X + 1, npc.Y, npc.Z)
npcRoot:PivotTo(CFrame.new(npcRoot:GetPivot().Position) * CFrame.Angles(0, math.rad(-90), 0))
end

--Tried3
while task.wait(0.2) do
npcRoot.CFrame += Vector3.new(npc.X + 1, npc.Y, npc.Z)
npcRoot:PivotTo(CFrame.new(npcRoot:GetPivot().Position) * CFrame.Angles(0, math.rad(-90), 0))
end
2 Likes

You can’t add cframes I believe only multiply them

how can i change position then

while task.wait(0.2) do
npcRoot.Position = Vector3.new(npc.X + 1, npc.Y, npc.Z)
npcRoot:PivotTo(CFrame.new(npcRoot:GetPivot().Position) * CFrame.Angles(0, math.rad(-90), 0))
end

try this.

4 Likes

Bro it will just change for 1 time, will not be loop.

1 Like

its because you are adding the current npc’s X position and the value you given

1 Like

why you typed this then? not my fault.

Bro the problem is already " HumanoidRootPart Poisiton Won’t Change While Loop"

and i made it now npcRoot.Position.X, yeah it loops now but it won’t move. It just turns around itself.

Are you trying to make a npc more forward or like change position every .2 sec?

npcRoot.CFrame = npcRoot.CFrame * CFrame.new(1, 0, 0)
and with the rotation
npcRoot.CFrame = npcRoot.CFrame * CFrame.new(1, 0, 0) * CFrame.Angles(0, math.rad(-90), 0)

it should be just move straight

The change the Z axis

npcRoot.CFrame = npcRoot.CFrame * CFrame.new(0, 0, -1) if its R6
npcRoot.CFrame = npcRoot.CFrame * CFrame.new(0, 0, 1) if its R15

Z makes it turn around itself too, won’t go straight. And i didn’t call myself a scripter man chill

Yo bro sorry man i thought it was a funny joke lol, but testing it for myself i saw it was turning too bro.
Why not uise humanoid:MoveTo()?

it worked right now but, will it be work for everyone? because i will use that code for players too. So it will change if they are R6 or R15

Why would you need it for players? Use pathfinding service or humanoid:MoveTo()

1 Like

Just remembered the MoveTo() Command.if you do in server,everybody will see it.if you do in client,only local player can see.

1 Like

thank you all! they really helped alot

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