How to make a player follow a player?

Hello, I am making a surrendering/capturing script. I am setting up so when you capture someone you can say “/cp [player] follow” to have them follow you, but i am having truble with the player following.

Script :

local Teams = game:GetService("Teams")
local Captured = {}
local Surrenderd = {}
local Surrender = game.ReplicatedStorage.Surrender
local Capturing = game.ReplicatedStorage.Capture
local Stage1 = game.ReplicatedStorage.CapturedLABEL
local stage1 = game.ReplicatedStorage.SurrenderedLABEL

Surrender.OnServerEvent:Connect(function(player)
	for p,s in pairs(Captured) do
		if p == player then
		else
			Surrenderd[player] = true
			local Head = player.Character:FindFirstChild("Head")

			local Cloned1 = stage1:Clone()
			local Cloned2 = Stage1:Clone()
			Cloned1.Parent = Head
			Cloned2.Parent = Head
		end
	end
	
	
	if Captured.Length == nil then
		Surrenderd[player] = true
		local Head = player.Character:FindFirstChild("Head")

		local Cloned1 = stage1:Clone()
		local Cloned2 = Stage1:Clone()
		Cloned1.Parent = Head
		Cloned2.Parent = Head
	end
	
end)

Capturing.OnServerEvent:Connect(function(player, CapturedPlayer)
	for s,d in pairs(Surrenderd) do
		if s == CapturedPlayer then
			Surrenderd[CapturedPlayer] = nil
			Captured[CapturedPlayer] = player
			local Head = CapturedPlayer.Character:FindFirstChild("Head")
			local STAGE1 = Head.CapturedLABEL
			local STAGE2 = Head.SurrenderedLABEL
			if STAGE1 and STAGE2 then
				STAGE1:Destroy()
				STAGE2:Destroy()
			end
		end
	end
end)

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		for CapturedPlayer, PlayerThatCaptured in pairs(Captured) do
			if player == CapturedPlayer then
				--do nothing
			elseif player == PlayerThatCaptured then
				if msg:match("/cp") then
					local words = string.split(msg, " ")
					local cp = words[2]
					local cmmd = words[3]
					if cmmd == "follow" or cmmd == "Follow" and cp == game.Players:GetFistChild(CapturedPlayer) then
						CapturedPlayer.DevTouchMovementMode = Enum.DevTouchMovementMode.Scriptable
						CapturedPlayer.DevComputerMovementMode = Enum.DevComputerMovementMode.Scriptable

							CapturedPlayer.Character.Humanoid:MoveTo(Vector3.new(PlayerThatCaptured.Character.HumanoidRootPart.Position)) -- it just moves them in a single direction and not towards me, i would also like it to update where to walk so when i change positions, it will keep on following
					end
					if cmmd == "endfollow" or cmmd == "Endfollow" and cp == game.Players:GetFistChild(CapturedPlayer)  then
						CapturedPlayer.DevTouchMovementMode = Enum.DevTouchMovementMode.UserChoice
						CapturedPlayer.DevComputerMovementMode = Enum.DevComputerMovementMode.UserChoice
					end
				end
			end
		end
	end)
end)
1 Like

Well if u would use pathfinding service and change the finish point constantly that would be possible