Tweening PivotTo() on a ServerScript for NPCs

My NPC is supposed to face the player when interacted and I have it working, but I would like it to tween smoothly.

I have tried looking at other posts, but none of them helped me because my situation is different. My NPCs are handled on a serverscript that runs different scripts depending on the NPCs name (stored in a table) e.g. Civilian, Suspicious Civilian. But it didn’t help my problem. Additionally, it would work for only one NPC, but make the other NPC of the same name bounce around the player.

A simple way of doing this like a tween is lerping. You can use :PivotTo() with a lookat cframe to face your NPC’s toward the player or whatever you want them to look at. could you give a little more context as to what exactly you are doing to all of the other NPC’s that may be affecting their position and causing the unwanted bouncing?

maybe that “one” npc that works with ur tween is the only one that have anchored enabled?

Neither one of them are anchored. They have wandering behavior that I am yet to implement properly.

A raycast from a tool sends a remote to the server, and the server tries to find the NPC with that name. It will then run the code for the NPC with that name on that NPC.

That is what is happening, but I’m not too sure what the issue could possibly be.

can u record a video of it?, cuz there is some reason, maybe the first frame of tweening got cancelled because the physics simulation changes the cframe (tween service stops the progress whenever the property gets overwritten by something else), try anchoring the npc humanoidrootpart before tweening them, also try to put prints along the way to test if the script even successfully locates the npc with the given name

I am completely stuck on what to do

you’re trying to get the npc with the same name to go in a circle around the player while bouncing, right?

local function LookAtFunc(Character : TheNPC, Target : Position)
	if Character.PrimaryPart then --just make sure the character's HRP has loaded
		local chrPos = Character.PrimaryPart.Position --get the position of the HRP
		local tPos = Target --get the position of the target
		local modTPos = (chrPos - tPos).Unit * Vector3.new(1,0,1) --mask out the Y axis
		local upVector = Character.PrimaryPart.CFrame.UpVector
		local newCF = CFrame.lookAt(chrPos, chrPos + modTPos, upVector) * CFrame.fromAxisAngle(Vector3.new(0, 1, 0), math.pi) --set the HRP's CFrame to our result, thus moving the character!
		return newCF
	end
end

local GetGoalCF = LookAtFunc(NPC, MyChar.PrimaryPart.Position)

game:GetService("TweenService"):Create(NPC.PrimaryPart, TweenInfo.new(Duration, Enum.EasingStyle.Linear), {CFrame = GetGoalCF}):Play()

also try anchoring the primarypart of the npc first before u tween, then unanchoring it again once the tween has finished