Unanchoring parts does not work

Hello
I have made a script that is supposed to unanchor all parts in an NPC and make them move to a point. The NPC is an R16 model, and the only part anchored at the beginning of the game is the HumanoidRootPart. When I run the script, no error occurs, but all of the NPC’s hover in the sky. If I look in the explorer, all of the parts I wanted to unanchored are. I am also making the player move to the same point.

for i, v in pairs(game.Workspace.WorkMap.Soldiers.GunSoldiers:GetChildren()) do
	if v.Name == "Soldier" then
		v.HumanoidRootPart.Anchored = false
		v.HumanoidRootPart.CFrame = CFrame.new(v.HumanoidRootPart.Position.X, v.HumanoidRootPart.Position.Y + 10, v.HumanoidRootPart.Position.Z) -- NPC's wont be stuck in an object
		v.Gun:Destroy()
		for a, part in pairs(v:GetChildren()) do
			if part:IsA("Part") or part:IsA("MeshPart") then
				part.Anchored = false -- Making sure all parts should be unanchored
			end
		end
	end
	v.Humanoid:MoveTo(playerPositions.SoldierMove1.Position) -- Move the NPC's to the point
end
game.Players.LocalPlayer.Character.Humanoid:MoveTo(playerPositions.SoldierMove1.Position) -- Move the player to the point

Here is a picture of what happens when I run the script:

Off in the distance, you can see that the player is moving to the point, but all of the NPC’s are hovering there. The one that is sitting down is not supposed to be moving, but the rest are. All the sandbags and parts in the NPC’s have CanCollide off, so they should not be getting stuck on anything.

Can anyone help me?

1 Like

LocalScripts are unable to change the .Anchored property. Instead you should manage the NPC movement using a Script(server script).

1 Like

Is there a way to do this for only one player using remoteEvents?

you need to do something like this

local Event = game.ReplicatedStorage.RemoteEvent
local player = – get the player

Event:FireServer(player)

local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player)
local plrName = player.Name
local char = game.Workspace:WaitForChild(plrName)
– Unanchor the player
end)

1 Like