How to add the enemies to the table just one time with the touched event?

ok, thanks bro, u are helping me a lot

whats the hitbox module?
ive noticed u have hitbox.onTouch = function(enemyHum) are u sure the “enemyHum” is always humanoid? (if enemyHum.ClassName ~= “Humanoid” then return end)

i think so pppppppppppsssssssss

let me see ggggggggggggggggggggggggg

do u mind putting print(enemyHum) under it and also print(hitedPeople)

yes, it is always a humanoid dddddddddddd

i’ll send a video wwwwwwwwwwwwwww

i think it will take some time jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj

also

getTarget(humanoidRootPart,enemy)

should be

local target, targetRP = getTarget(humanoidRootPart,enemy)

because ive noticed, somewhere under it have task.wait() meaning after that wait, the target could be changed because the target variable is way above it

lets see if it works bbbbbbbbbbbbbbb

no it didnt works :smiling_face_with_tear: i dont know what to do

lets debug it, try adding this

if tick() - startTick > 3 then	
print(target, targetRP)

on ur

					if tick() - startTick > 3 then	
						print(target, targetRP)
						character:SetAttribute("Grab",false)
						target.Humanoid.PlatformStand = false
						humanoid.WalkSpeed = 20
						humanoid.JumpPower = 50

just add the print one

try the game again and show us the output during those moments

it prints normal but the targetRP print two times, even when the target is the farthest

can we see the current script? il read it after all these changes

ok.

local grabRemote = RP.remotes.grab
local ss = game:GetService("ServerStorage")
local modules = ss:WaitForChild("Modules")
local slow = require(modules:WaitForChild("slow"))
local runService = game:GetService("RunService")
local rockModule = require(modules:WaitForChild("RockModule"))
local utilities = require(modules:WaitForChild("particleEmitter"))
local hitbox = require(modules:WaitForChild("hitbox"))
local hitService = require(modules:WaitForChild("hitService"))

local hitedPeople = {}
local grabAnins = {}

local looping = false

local startTick
local weld
local enemy
local enemyHumRP
local closestDist = math.huge
local target = nil
local targetRP = nil

local function aplyVelocity(targetHumRP,direction)
	local linearV = Instance.new("LinearVelocity",targetHumRP)
	local attach = targetHumRP.RootAttachment
	linearV.MaxForce = 100000
	linearV.ForceLimitMode = Enum.ForceLimitMode.PerAxis
	linearV.MaxAxesForce = Vector3.new(100000,0,100000)
	linearV.VectorVelocity = direction
	linearV.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
	linearV.Attachment0 = attach
	linearV.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	attach.WorldPosition = targetHumRP.AssemblyCenterOfMass
	linearV.ForceLimitsEnabled = true
	game.Debris:AddItem(linearV,0.2)
end

local function getTarget(hrp,enemy)
	closestDist = math.huge
	target = nil
	targetRP = nil
	
	if #hitedPeople > 0 then
		for i,enemyChar in pairs(hitedPeople) do
			local enemyRP = enemyChar.HumanoidRootPart
			local distance = (enemyRP.RootAttachment.WorldPosition - hrp.RootAttachment.WorldPosition).Magnitude

			if distance < closestDist then
				closestDist = distance
				target = enemyChar
				targetRP = target.HumanoidRootPart
			end
		end	
	end
	
	return target,targetRP,closestDist
end	

grabRemote.OnServerEvent:Connect(function(plr,grab,input)	
	local character = plr.Character
	local humanoid = character:WaitForChild("Humanoid")
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	
	local grabing = character:GetAttribute("Grab")
	local attacking = character:GetAttribute("Attacking")
	local punching = character:GetAttribute("Punching")
	local blocking = character:GetAttribute("Blocking")
	local jumping = character:GetAttribute("Jumping")
	local slowed = character:GetAttribute("Slowed")
	local stunned = character:GetAttribute("Stunned")
	local dashing = character:GetAttribute("Dash")
	local dashing2 = character:GetAttribute("Dash2")
	
	if grab then
		if grabing or attacking or punching or blocking or stunned or dashing or dashing2 then return end
	
    	local animation = Instance.new("Animation")
    	animation.AnimationId = "http://www.roblox.com/asset/?id=85032147152709"
    	local animationTrack = humanoid:LoadAnimation(animation)
	
    	local animationGrabing = Instance.new("Animation")
    	animationGrabing.AnimationId = "http://www.roblox.com/asset/?id=anim"
    	local animationTrackGrabing = humanoid:LoadAnimation(animationGrabing)
	
    	local hitbox = hitbox.new()
    	hitbox.Size = Vector3.new(14,14,14)
    	hitbox.CFrame = humanoidRootPart
    	hitbox.Offset = CFrame.new(0,0,-2)
		hitbox.Visualizer = true
		
		hitbox.onTouch = function(enemyHum)
			if enemyHum ~= humanoid then				
				looping = true
				character:SetAttribute("Grab",true)
	        	enemy = enemyHum.Parent
				enemyHumRP = enemy.HumanoidRootPart
				
				if table.find(hitedPeople,enemy) == nil then
					table.insert(hitedPeople,enemy)	
				end
				
				local target, targetRP = getTarget(humanoidRootPart,enemy)
				
				print(hitedPeople)
				print(target)
				
				for i,v in pairs(target:GetChildren()) do
					if v:IsA("BasePart") then
						v.Color = Color3.fromRGB(0,100,80)
					end
				end
				
					weld = Instance.new("Weld")
					weld.C1 = CFrame.new(0,0,-2) * CFrame.Angles(0,math.rad(180),0)
					weld.Part0 = targetRP
					weld.Part1 = humanoidRootPart
					weld.Name = "wellwellwell"
				
					local knockback = nil
					local maxForce = nil
				
					startTick = tick()
				
					while looping do
						humanoid.WalkSpeed = 10
						humanoid.JumpPower = 0
				
						weld.Parent = targetRP
						target.Humanoid.PlatformStand = true
				
					
						if tick() - startTick > 3 then			
							print(target,targetRP)
							character:SetAttribute("Grab",false)
							target.Humanoid.PlatformStand = false
							humanoid.WalkSpeed = 20
							humanoid.JumpPower = 50

							for i,v in pairs(targetRP:GetChildren()) do
								if v:IsA("Weld") and v.Name == "wellwellwell" then
									v.Parent = nil
								end
							end
							
						
							aplyVelocity(targetRP,Vector3.new(0,0,30))
							
							hitedPeople = {}
													
							break
						end
				
						task.wait()
					end
				
					hitService.hit(enemyHum,nil,knockback,nil,character,nil,nil,maxForce,nil,nil)
					
			end	
		end
	
		animationTrack.KeyframeReached:Connect(function(kf)
			if kf == "grab" then
				hitbox:Start()
				task.wait(0.2)
				hitbox:Stop()
			end
		end)
	
		animationTrack:Play()
		grabAnins[plr] = animationTrack
	else
		if grabing then				
			looping = false
			character:SetAttribute("Grab",false)
			grabAnins[plr]:Stop()
			grabAnins[plr] = nil
			
			humanoid.WalkSpeed = 20
			humanoid.JumpPower = 50
			
			target.Humanoid.PlatformStand = false
			
			for i,v in pairs(targetRP:GetChildren()) do
				if v:IsA("Weld") and v.Name == "wellwellwell" then
					v.Enabled = false
				end
			end
			
			if tick() - startTick < 3 and input == Enum.KeyCode.T then
				aplyVelocity(targetRP,Vector3.new(0,0,30))
			elseif input == Enum.KeyCode.Y then
				aplyVelocity(targetRP,Vector3.new(30,0,0))
			elseif input == Enum.KeyCode.G then
				aplyVelocity(targetRP,Vector3.new(-30,0,0))
			end			
			
			hitedPeople = {}
		end
		
	end	
end)

let me ask this, the main problem is that the getTarget function is giving u the farthest enemy right?

yes, but not all the time, sometimes the function give me the two dummies

u mean it grabs 2 dummies at the same time?

yes fggfhgrhsrwtherthdsfgdsrth

i think ur hitbox.onTouch is triggering multiple times within this 0.2 seconds

			if kf == "grab" then
				hitbox:Start()
				task.wait(0.2)
				hitbox:Stop()
			end

try putting using this script

local grabRemote = RP.remotes.grab
local ss = game:GetService("ServerStorage")
local modules = ss:WaitForChild("Modules")
local slow = require(modules:WaitForChild("slow"))
local runService = game:GetService("RunService")
local rockModule = require(modules:WaitForChild("RockModule"))
local utilities = require(modules:WaitForChild("particleEmitter"))
local hitbox = require(modules:WaitForChild("hitbox"))
local hitService = require(modules:WaitForChild("hitService"))

local hitedPeople = {}
local grabAnins = {}

local looping = false

local startTick
local weld
local enemy
local enemyHumRP
local closestDist = math.huge
local target = nil
local targetRP = nil

local function aplyVelocity(targetHumRP,direction)
	local linearV = Instance.new("LinearVelocity",targetHumRP)
	local attach = targetHumRP.RootAttachment
	linearV.MaxForce = 100000
	linearV.ForceLimitMode = Enum.ForceLimitMode.PerAxis
	linearV.MaxAxesForce = Vector3.new(100000,0,100000)
	linearV.VectorVelocity = direction
	linearV.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
	linearV.Attachment0 = attach
	linearV.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
	attach.WorldPosition = targetHumRP.AssemblyCenterOfMass
	linearV.ForceLimitsEnabled = true
	game.Debris:AddItem(linearV,0.2)
end

local function getTarget(hrp,enemy)
	closestDist = math.huge
	target = nil
	targetRP = nil

	if #hitedPeople > 0 then
		for i,enemyChar in pairs(hitedPeople) do
			local enemyRP = enemyChar.HumanoidRootPart
			local distance = (enemyRP.RootAttachment.WorldPosition - hrp.RootAttachment.WorldPosition).Magnitude

			if distance < closestDist then
				closestDist = distance
				target = enemyChar
				targetRP = target.HumanoidRootPart
			end
		end	
	end

	return target,targetRP,closestDist
end	

grabRemote.OnServerEvent:Connect(function(plr,grab,input)	
	local character = plr.Character
	local humanoid = character:WaitForChild("Humanoid")
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")

	local grabing = character:GetAttribute("Grab")
	local attacking = character:GetAttribute("Attacking")
	local punching = character:GetAttribute("Punching")
	local blocking = character:GetAttribute("Blocking")
	local jumping = character:GetAttribute("Jumping")
	local slowed = character:GetAttribute("Slowed")
	local stunned = character:GetAttribute("Stunned")
	local dashing = character:GetAttribute("Dash")
	local dashing2 = character:GetAttribute("Dash2")

	if grab then
		if grabing or attacking or punching or blocking or stunned or dashing or dashing2 then return end

		local animation = Instance.new("Animation")
		animation.AnimationId = "http://www.roblox.com/asset/?id=85032147152709"
		local animationTrack = humanoid:LoadAnimation(animation)

		local animationGrabing = Instance.new("Animation")
		animationGrabing.AnimationId = "http://www.roblox.com/asset/?id=anim"
		local animationTrackGrabing = humanoid:LoadAnimation(animationGrabing)

		local hitbox = hitbox.new()
		hitbox.Size = Vector3.new(14,14,14)
		hitbox.CFrame = humanoidRootPart
		hitbox.Offset = CFrame.new(0,0,-2)
		hitbox.Visualizer = true
		
		local onTouchGoing = false
		hitbox.onTouch = function(enemyHum)
			if onTouchGoing == true then return end
			if enemyHum ~= humanoid then				
				looping = true
				character:SetAttribute("Grab",true)
				enemy = enemyHum.Parent
				enemyHumRP = enemy.HumanoidRootPart

				if table.find(hitedPeople,enemy) == nil then
					table.insert(hitedPeople,enemy)	
				end

				local target, targetRP = getTarget(humanoidRootPart,enemy)
				
				if target ~= nil then
					onTouchGoing = true
				end
				
				print(hitedPeople)
				print(target)

				for i,v in pairs(target:GetChildren()) do
					if v:IsA("BasePart") then
						v.Color = Color3.fromRGB(0,100,80)
					end
				end

				weld = Instance.new("Weld")
				weld.C1 = CFrame.new(0,0,-2) * CFrame.Angles(0,math.rad(180),0)
				weld.Part0 = targetRP
				weld.Part1 = humanoidRootPart
				weld.Name = "wellwellwell"

				local knockback = nil
				local maxForce = nil

				startTick = tick()

				while looping do
					humanoid.WalkSpeed = 10
					humanoid.JumpPower = 0

					weld.Parent = targetRP
					target.Humanoid.PlatformStand = true


					if tick() - startTick > 3 then			
						print(target,targetRP)
						character:SetAttribute("Grab",false)
						target.Humanoid.PlatformStand = false
						humanoid.WalkSpeed = 20
						humanoid.JumpPower = 50

						for i,v in pairs(targetRP:GetChildren()) do
							if v:IsA("Weld") and v.Name == "wellwellwell" then
								v.Parent = nil
							end
						end


						aplyVelocity(targetRP,Vector3.new(0,0,30))

						hitedPeople = {}

						break
					end

					task.wait()
				end

				hitService.hit(enemyHum,nil,knockback,nil,character,nil,nil,maxForce,nil,nil)

			end	
		end

		animationTrack.KeyframeReached:Connect(function(kf)
			if kf == "grab" then
				hitbox:Start()
				task.wait(0.2)
				hitbox:Stop()
				onTouchGoing = false
			end
		end)

		animationTrack:Play()
		grabAnins[plr] = animationTrack
	else
		if grabing then				
			looping = false
			character:SetAttribute("Grab",false)
			grabAnins[plr]:Stop()
			grabAnins[plr] = nil

			humanoid.WalkSpeed = 20
			humanoid.JumpPower = 50

			target.Humanoid.PlatformStand = false

			for i,v in pairs(targetRP:GetChildren()) do
				if v:IsA("Weld") and v.Name == "wellwellwell" then
					v.Enabled = false
				end
			end

			if tick() - startTick < 3 and input == Enum.KeyCode.T then
				aplyVelocity(targetRP,Vector3.new(0,0,30))
			elseif input == Enum.KeyCode.Y then
				aplyVelocity(targetRP,Vector3.new(30,0,0))
			elseif input == Enum.KeyCode.G then
				aplyVelocity(targetRP,Vector3.new(-30,0,0))
			end			

			hitedPeople = {}
		end

	end	
end)

i added debounce (“onTouchGoing”) and (if target ~= nil then onTouchGoing = true)