Player Clone doesn't target anyone

Hello Developers!

As stated in the title, a clone of the player doesn’t follow anyone.

llocal Tool = script.Parent
local DrinkEvent = Tool:WaitForChild("Drinking")
--//Services\\--
local Plrs = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local Deb = game:GetService("Debris")
local PFS = game:GetService("PathfindingService")
local RunS = game:GetService("RunService")
--//Connections\\--
DrinkEvent.OnServerEvent:Connect(function(Plr)
	local Character = Plr.Character or Plr.CharacterAdded:Wait()
	Character.Archivable = true
	
	local CharClone = Character:Clone()
	CharClone.Parent = game.Workspace
	Deb:AddItem(CharClone,5)
	CharClone.Name = "The Totally Real "..Character.Name.."! Trust me, he's real."
	CharClone.HumanoidRootPart.CFrame = CharClone.HumanoidRootPart.CFrame + Vector3.new(0, 0, -2)
	local DeathClockTimer = 5
	
	local function FindNearestEnemy()
		local Enemies = {}
		local Nearest = math.huge
		local Target = nil
		
		
		for _, Enemy in pairs(workspace:GetChildren()) do
			if Enemy:IsA("Model") then
				local Distance = (Enemy.PrimaryPart.Position - Character.PrimaryPart.Position)
				if Distance.Magnitude < Nearest and Enemy.Name ~= Plr.Name then
					table.insert(Enemies,{
						Magnitude = Distance.Magnitude,
						enemy = Enemy
					})
				end
			end
		end
		for _, Entry in pairs(Enemies) do
			local magntiude = Entry.Magnitude
			local enemy = Entry.enemy
			
			if magntiude < Nearest then
				Nearest = magntiude
				Target = enemy
			end
		end
		return Target
	end
	
	RunS.Stepped:Connect(function()
		local enemy = FindNearestEnemy()
		
		local Destination = enemy.PrimaryPart.Position
		local Beginning = Character.PrimaryPart.Position
		
		local Path = PFS:CreatePath()
		Path:ComputeAsync(Beginning,Destination)
		if Path.Status == Enum.PathStatus.Success then
			local Waypoints = Path:GetWaypoints()

			if Waypoints and Waypoints[2] then
				local Data = Waypoints[2]
				CharClone.Humanoid:MoveTo(Data.Position)
			end
		end
	end)
end)

Nevermind, I think I found it a solution, but it breaks. New post ig

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.