Issue - Script moves NPC to a part, but the NPC re-teleports back to its prev. position right away

So, I’ve been trying to figure this out and it absolutely makes no sense at all.

I have a script which moves a NPC’s HumanoidRootPart to a specific part’s position. However, when the NPC gets moved to the part (it’s noticeable on the screen), it gets teleported back to its previous position in an instant.

Code line:
game.Workspace.NPC.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.TP2.Position)

I’m confused cause the line itself has no issues and doesn’t produce errors. The player isn’t anchored either.

Any ideas what it could be?

1 Like

Can you display a gif of the problem happening?

1 Like

Just take this as an example:

  • You have Point A and Point B - the NPC is standing on Point A
  • You’re teleporting the NPC to Point B by that line above
  • On your screen, you will notice that the NPC moved to Point B for a milisecond, but right after that, the NPC will go back to Point A

(I’ll take a GIF later)

1 Like
workspace.NPC.HumanoidRootPart.CFrame = workspace.TP2.CFrame -- if 'TP2' is a model set a part as the primary part, and instead do 'workspace.TP2.YourPart.CFrame'
2 Likes

Tried that, too. Unfortunately, it teleports back right away.

This is actually confusing me, the line has absolutely no errors and would work in any case.

Is ‘TP2’ a model? (30 charsssss)

1 Like

No, it’s a part. Also, incase if this is useful:

I tried using both normal and a LocalScript (server-sided work isn’t bothering me atm, it’s just for a video package so I’m using LocalScripts) and the issue is still there. At first, I thought it was happening due to it being a LocalScript, but same things occurs.

It works for me, I put my code in a serverscript in serverscriptservice (Sorry for not telling you that)

Do you have any other scripts doing things with the NPC?

Well, it runs an animation right after it gets teleported.

(Sorry for not mentioning) It has to be in StarterGui - need it for camera manipulation. Server-sided teleportation for the NPC doesn’t bother me atm. Regardless, it doesn’t work with a normal script either.

You can use remote events

function StartManip()
     -- camera manip code
     game.ReplicatedStorage.RemoteEvent1:FireSever()
 end)
StartManip()
-- serverscript in serverscriptservice
game.ReplicatedStorage.RemoteEvent1.OnServerEvent:Connect(function()
   workspace.NPC.HumanoidRootPart.CFrame = workspace.TP2.CFrame
end)
1 Like

Tried using RemoteEvents as well - no success.
I’ll try your suggestion tho.

A Script runs if it is a descendant of the Workspace of ServerScriptService and isn’t disabled.
A LocalScript Runs if it is in:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service
    This is according to the DeveloperHub.
1 Like

I’m aware of that. I was using a regular script for a RemoteEvent and a LocalScript for UI-related work.

Wait are you using a serverscript to do the camera manip?

No, the camera manipulation is being handled in a player’s GUI.

is the script a local script or a serverscript?

A LocalScript.

Anyway; apparently, it was the studio being outdated even tho I restarted it 10 times. I just updated it and everything works as it should.

Thanks for helping! Your code should also work as well as it looks totally fine, so that should be a solution as well.

1 Like