Clone keeps focusing on a lobby and npc and find no ones if we skip it

  1. I want to achieve a player cloning ability allowing the clone to find all the characters containing an Humanoid in the workspace and filtering the Humanoid owner and other npc that are banned from the focus

  2. **The issue is below it follow one Humanoid Potition of one npc we put on the lobby of one of our dev. if your asking i put a free model killer noob since it should attack him normally.

  1. I tryed to use Tag and attribute on all the npc statue of the lobby:

image_2024-08-19_214934000

Basically the Clone should attack the free model killing noob instead of gettings into the player in lobby since the position is the nearest and it doesn’t which is pretty strange for me.

local function findNearestPlayer(character,originalCharacter)
	local nearestPlayer = nil
	local nearestDistance = math.huge

	for _, targetCharacter in workspace:GetDescendants() do
		if not character or not character:FindFirstChild("HumanoidRootPart") then break end
		
		if character and targetCharacter and targetCharacter:FindFirstChild("Humanoid") and targetCharacter:FindFirstChild("Humanoid").Health > 0 and targetCharacter:FindFirstChild("HumanoidRootPart") and targetCharacter.Parent.Name ~= "Clones" and targetCharacter ~= originalCharacter  then
			
			local distance = (targetCharacter.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude
			if distance < nearestDistance then
				nearestDistance = distance
				nearestPlayer = targetCharacter
			end
		end
		
	end

	return nearestPlayer
end

local function followNearestPlayer(clone,originalcharacter)
	while clone do
		if not clone:FindFirstChild("Humanoid") then
			break
		end
		
		local nearestPlayer = findNearestPlayer(clone,game.Players[clone.Name].Character)

		if not nearestPlayer and originalcharacter then
			clone.Humanoid:MoveTo(originalcharacter.HumanoidRootPart.Position + Vector3.new(6,0,0))
		end
		
		print(nearestPlayer)

		if nearestPlayer then
			clone.Humanoid:MoveTo(nearestPlayer.HumanoidRootPart.Position + Vector3.new(6,0,0))
		else
			print("no nearest player")
		end
		task.wait(0.5)
	end
end

local function clonecharacter(originalCharacter)
	if not workspace:FindFirstChild("Clones") then 
	local folder = Instance.new("Folder",workspace)
	folder.Name = "Clones"
	end
	
	local newcharacter = originalCharacter:Clone()
	newcharacter.HumanoidRootPart.CFrame = originalCharacter.HumanoidRootPart.CFrame + Vector3.new(5, 10, 0)
	newcharacter.Parent = workspace.Clones
	local animscript = game.ServerStorage.ReplicableScripts["Animate"]:Clone()
	animscript.Parent = newcharacter
	animscript.Enabled = true

	task.spawn(followNearestPlayer, newcharacter,originalCharacter) -- Start following the nearest player in a separate thread

	-- Continuously create the hitbox for the clone
	task.spawn(createHitbox, newcharacter, originalCharacter)
	
	task.spawn(DespawnOnDeath,newcharacter)

	-- Destroy the clone after 30 seconds
	task.wait(120)
	if newcharacter then
		newcharacter:Destroy()
	end
	if #workspace.Clones:GetChildren() < 1 then
		workspace.Clones:Destroy()
	end
end

Hope you understand what i wanted to do else you can just ask i will try specify more what the clone used to do normally.

I removed the :HasTag() and the :GetAttribute()

1 Like

image_2024-08-20_021854239

I think i fixed the problem by myself and also this allows the clone to be nerfed a little bit since its overpowered.

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