:MoveTo doesn't work

Hi,
Im trying to make an arrest system.
As one option, you should be able to move the arrested player to you, so he is following you. I tried that using :MoveTo but it’s not working. There are no errors and the player just stands still.

Here’s the part where I think the error is:

for i, v in pairs(target) do
			moving = true
			while moving == true do
				wait(0.1)
				v.Humanoid:MoveTo(Vector3.new(plr.Character.HumanoidRootPart.Position))
				v.Humanoid.MoveToFinished:Connect(function()
					moving = false
				end)
			end
		end

The full script:

local rep = game:GetService("ReplicatedStorage"):WaitForChild("ArrestEvent")

local cuffedPlayers = {}

local UnloadedAnim = script.Parent.Animation

onGoing = false
moving = false

rep.OnServerEvent:Connect(function(plr, target, method)
	if method == 1 then
		local hum = target:FindFirstChild("Humanoid")
		local Anim = hum:LoadAnimation(UnloadedAnim)
		if table.find(cuffedPlayers, target.Name) then
			table.remove(cuffedPlayers, table.find(cuffedPlayers, target.Name))
			rep:FireClient(plr, target)
			
			--local controls = require(target.LocalPlayer.PlayerScripts:FindFirstChild("PlayerModule"):GetControls())
			--controls:Enable()
			
			Anim:AdjustSpeed(0.9)
			
		else
			if onGoing == false then
				onGoing = true
				
				table.insert(cuffedPlayers, target.Name)
				
				Anim:Play()
				wait(0.8)
				Anim:AdjustSpeed(0)
				
				--local controls = require(target.LocalPlayer.PlayerScripts:FindFirstChild("PlayerModule"):GetControls())
				--controls:Disable()
				
				onGoing = false
			end
		end
		
		
		
	elseif method == 2 then
		for i, v in pairs(target) do
			moving = true
			while moving == true do
				wait(0.1)
				v.Humanoid.MoveToFinished:Connect(function()
					moving = false
				end)
				v.Humanoid:MoveTo(Vector3.new(plr.Character.HumanoidRootPart.Position))
			end
		end
	end
end)

The local script:

wait(1)

local plr = game.Players.LocalPlayer

local mouse = game.Players.LocalPlayer:GetMouse()

local rep = game:GetService("ReplicatedStorage"):WaitForChild("ArrestEvent")
local UI = plr.PlayerGui:FindFirstChild("ArrestUI")

local BodyParts = {"Head", "Left Arm", "Right Arm", "Right Leg", "Left Leg", "HumanoidRootPart", "Torso", }
local cuffed = {}



script.Parent.Activated:Connect(function()
	if mouse.Target then
		if table.find(BodyParts, mouse.Target.Name) then
			local target = mouse.Target.Parent
			table.insert(cuffed, target)
			rep:FireServer(target, 1)
		end
	end
end)

rep.OnClientEvent:Connect(function(target)
	table.remove(cuffed, table.find(cuffed, target))
end)

script.Parent.Equipped:Connect(function()
	UI.Frame.Visible = true
end)

script.Parent.Unequipped:Connect(function()
	UI.Frame.Visible = false
end)

UI.Frame.Follow.MouseButton1Click:Connect(function()
	rep
1 Like

try this one

for i, v in pairs(target) do
			moving = true
			while moving == true do
				wait(0.1)
                v.Humanoid.MoveToFinished:Connect(function()
					moving = false
				end)
				v.Humanoid:MoveTo(Vector3.new(plr.Character.HumanoidRootPart.Position))
			end
		end
2 Likes

im not sure if movetofinished is an event can you clarify

So this is really weird what happens now…
So first time trying it, the cuffedMan moves just a bit and stops and then nothing happens. If I try it with the other person, it works but then not a second time. I provided now also the full script, cause maybe the problem is there.

It is, I looked up to it and its an avaible event

moveto is instant with every physics frame. there’s zero need for a debounce since your thread already has an execution order.

Well I read, that if the target doesnt reach his goal in idc seconds 8 or sth, it will just get cancelled so thats why I did it

moveto has no regard for physics and is a straight “cframe manipulation tool” and will instantly teleport.
make your script like this

for i, v in pairs(target) do
			while true do
           v.PrimaryPart:MoveTo(--blah blah
            end
		end
1 Like

you can just position the arrested player infront of the cop then weld him

That doesnt work. The player just doesnt move at all with this:

for i, v in pairs(target) do

			while true do
				wait(0.2)
				v.PrimaryPart:MoveTo(Vector3.new(plr.Character.Torso.Position))
			end
		end

Wouldnt he then stick to him? Like some distance between both players would be good

also i just realized why are you using a in pairs loop…??

do this

while arrested do
				wait(0.2)
				v.PrimaryPart:MoveTo(Vector3.new(plr.Character.Torso.Position))
			end
		end

Reason for the loop is, because target is a table with all cuffedPlayers in it and all players who are cuffed by this Person should move to him so thats why.

When I try:

for i, v in pairs(target) do
			target.HumanoidRootPart.CFrame = CFrame.new(plr.Character.HumanoidRootPart.CFrame.X + 10, plr.Character.HumanoidRootPart.CFrame.Y, plr.Character.HumanoidRootPart.CFrame.Z)
		end

I get this error:
Players.Faustollol.Backpack.Arrest.Script:44: attempt to index nil with ‘CFrame’

did you try the solution i sent because you aren’t getting errors which means the loop isnt firing. also groups are instances so using pairs is bad, use ipairs

Yeah I tried it and the player is just not moving at all

put prints everywhere on the client where it sends the data and on the server and tell me if it sends you anything and what it sends and ill try to help from there

network ownership would probably bug that out (maybe) is what im thinking

Sorry for my understanding you want make a system were what? Can you it pleas explain.thx
LG zab

Are you calling MoveTo() on the humanoid so it follows you?

-- Get the Humanoid object of the follower
local targetHumanoid = targetCharacter:FindFirstChild("Humanoid")

local function Follow()
    while true do
        -- Check if the target player has a character
        if targetPlayer.Character then
            local targetPosition = targetPlayer.Character:GetPrimaryPartCFrame().Position
            targetHumanoid:MoveTo(targetPosition) -- Use MoveTo to move towards the target
        end
        wait(0.1) -- Adjust the update frequency as needed
    end
end

If you want to move the model itself, you can use :SetPrimaryPartCFrame() (I believe this is going to be depreciated) or :PivotTo() instead.

1 Like