You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want an NPC to be able to move with
Humanoid:MoveTo() while aiming on a position without canceling the “:MoveTo()” -
What is the issue? I try use Model:PivotTo() on the NPC but it cancels the “:MoveTo()”
-
What solutions have you tried so far? I found this with a solution but I dont understand anything about it
In conclusion, I want the NPC model to be able to rotate or aim while being able to move using the Humanoid:MoveTo()
local rep = game.ReplicatedStorage
local exc = game.ReplicatedStorage.Stuff.ExclamanationMark
rep:WaitForChild("Remotes"):WaitForChild("MoveCommand").OnServerEvent:Connect(function(plr,mcframe, right)
local rig = game.Workspace.Rig
if right then
if game.Workspace:FindFirstChild("ExclamanationMark") then game.Workspace.ExclamanationMark:Destroy() end
local excc = exc:Clone()
excc.Position = mcframe.Position
excc.Parent = game.Workspace
rig.Humanoid:MoveTo(mcframe.Position)
else
local targetCFrame = CFrame.new(rig.PrimaryPart.Position, mcframe.Position)
local _, targetY, _ = targetCFrame:ToOrientation()
local targetYDegrees = math.deg(targetY)
print("Target Y orientation (degrees):", targetYDegrees)
local currentCFrame = rig:GetPivot()
local position = currentCFrame.Position
local currentX, _, currentZ = currentCFrame:ToOrientation()
-- Create a new CFrame with only the Y orientation changed
local newCFrame = CFrame.new(position) * CFrame.Angles(currentX, math.rad(targetYDegrees), currentZ)
rig:PivotTo(newCFrame)
end
end)
CFrame is very confusing to me, please give some explanation on it, thank you.