How to make a script that only works on one player

Hello everybody. If the title’s a bit confusing, let me explain. So I’m making a move where a player grabs an opponent and punches them, followed by a dropkick. I was pretty proud with the results, but theres this one issue I can’t seem to find a solution to. The grab move grabs multiple enemies that were hit by the attack, even though it was only meant to grab one player. This led to a lot of issues, most of them being how it looked. It looked horrible, it made the game looked bad. This is how the move was suppose to work:

https://gyazo.com/88d34d8c5274db9d6a2342f9c049cd86

Not bad for a beginner, but heres how it looks when you grab multiple enemies:

https://gyazo.com/78937a2349aef0411f6a009ce3ad3832

It’s a mess, not only does it look weird, but the opponents gets glitched sometimes, this is really frustrating, and I knew I won’t be able to find a solution to this problem alone.

This is the script that holds the opponent to the player’s left arm.

game.ReplicatedStorage.Main.SpecialMoves.Hold.OnServerEvent:Connect(function(player, enemy, length)
	local Chr = player.Character
	local Hrp = Chr.HumanoidRootPart
	local leftarm = Chr["Left Arm"]
	local Shockedvalue = enemy:FindFirstChild("Shocked").Value
	
	local GHrp = enemy.HumanoidRootPart
	
	local Thing = Instance.new("BodyPosition", GHrp)
	Thing.P = 50000
	Thing.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	Thing.Position = Hrp.Position + Hrp.CFrame.LookVector * 5 --
	
	local holding = false
	
	coroutine.resume(coroutine.create(function()
		GHrp.Parent:WaitForChild("Humanoid")
		Hrp.Anchored = true
		GHrp.Parent.Humanoid:LoadAnimation(script.Animation):Play()
		wait(length)
		holding = true
		GHrp.Parent.Humanoid:LoadAnimation(script.Animation):Stop()
		Hrp.Anchored = false
	end))
		
	repeat
		Shockedvalue = true
		wait()
		Thing.Position = Hrp.Position + Hrp.CFrame.LookVector * 2
	until holding == true
	
	Thing:Destroy()
	Shockedvalue = false
end)

I’m not really sure if the grab script is good, I’m pretty sure it’s not but this is the only way I know on how to make a beatdown.

This is the local script, there are 2 function, the first function is the one that detects if the attack has hit a player, the second function is, well, it’s just the main function, with the animation and stuff.

1st Function:

-- Grab Hitbox
function grabhitbox(partoz, partcfr, magn, dmg, debtim, debtime, bodyfdire, effect, grow, color, soundid, volume)
	if Fainted.Value == true then return end
	for _, guy in pairs(workspace.Living:GetChildren()) do
		if partoz.Anchored == true then return end
		if guy:FindFirstChild("Humanoid") and guy:FindFirstChild("HumanoidRootPart") and guy ~= chr and magn > (guy:FindFirstChild("HumanoidRootPart").Position - partoz.Position).magnitude and guy:FindFirstChild("HumanoidRootPart"):FindFirstChild("DBT") == nil then
			do
				if partoz.Anchored then return end
				local humz = guy:FindFirstChild("Humanoid")
				local horp = guy:FindFirstChild("HumanoidRootPart")
				damageevent:FireServer(humz, partcfr, dmg+DamageMultiplier, debtime, bodyfdire, soundid, volume)
				GrabEvent:FireServer(guy, 4)
				Grabbed = true
				--RagdollEvent:FireServer(humz)
				local db = Instance.new("StringValue")
				db.Name = "DBT"
				db.Parent = horp
				delay(debtim, function()
					db:Destroy()
				end)
			end
		end
		if guy:FindFirstChild("Stand") and guy["Stand"]:FindFirstChild("Stand Torso") and guy ~= chr and guy ~= chr[stand.Name] and magn > (guy["Stand"]:FindFirstChild("Stand Torso").Position - partoz.Position).magnitude and guy:FindFirstChild("HumanoidRootPart"):FindFirstChild("DBT") == nil then
			do   
				if partoz.Anchored then return end
				local humz = guy:FindFirstChild("Humanoid")
				local horp = guy:FindFirstChild("HumanoidRootPart")
				damageevent:FireServer(humz, partcfr, dmg+DamageMultiplier, debtime, bodyfdire, soundid, volume)
				GrabEvent:FireServer(guy, 4)
				Grabbed = true
			--	RagdollEvent:FireServer(humz)
				local db = Instance.new("StringValue")
				db.Name = "DBT"
				db.Parent = horp
				delay(debtim, function()
					db:Destroy()
				end)
			end
		end
	end
end

2nd Function:

-- Power Combo
local currenthealth = human.Health
local oldws,oldjp = human.WalkSpeed, human.JumpPower
function Powercombo()
	--// Cooldown and Performing Check\\--
	if PowerComboCD.Value == true or PerformingAction.Value == true or Stunned.Value == true then return end
	--// Applying the Changes\\--
	PerformingAction.Value = true
	PowerComboCD.Value = true
	--// Main Function \\--
	human.WalkSpeed = 6
	human.JumpPower = 0
	playAnim(8264441510)
	wait(.5)
	comboreadysfx:Play()
	coroutine.resume(coroutine.create(function()
		for _ = 1,3 do
			task.wait()
			grabhitbox(rightarm, rightarm.CFrame * CFrame.new(0, -1, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,3, 1, 0.75, 0.25, hrp.CFrame.lookVector * 0, "rbxassetid://580201163", 0.075, Color3.new(1, 1, 1), 6690141385, 2)
		end
	end))
	human.WalkSpeed = oldws
	human.JumpPower = oldjp
	wait(.5)
	if Grabbed == true then
		human.WalkSpeed = 0
		human.JumpPower = 0
		kismashevent:FireServer()
		PunchReadyAnim:Play()
		PunchHoldAnim:Play()
		energyevent:FireServer()
		ChargeNoise:Play()
		ChargeNoise.Ended:Wait()
		PunchHoldAnim:Stop()
		coroutine.resume(coroutine.create(function()
			comboblue.Enabled = true
			ChargeVC:Play()
			fovadjuster.Adjust(120,0.3)
			wait(.5)
			comboblue.Enabled = false
			fovadjuster.Adjust(70,0.4)
		end))
		PunchReleaseAnim:Play()
		human.WalkSpeed = oldws
		human.JumpPower = oldjp
		coroutine.resume(coroutine.create(function()
			for _ = 1,2 do
				wait(.25)
				bloodyhitbox(rightarm, rightarm.CFrame * CFrame.new(0, -1, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,3, 25, 0.75, 0.25, hrp.CFrame.lookVector * 50, "rbxassetid://6690082443", 0.075, Color3.new(1, 1, 1), 6690665484, 2)
			end
		end))
	else
		
	end
	--// Cooldown\\--
	Grabbed = false
	PerformingAction.Value = false
	coroutine.resume(coroutine.create(function()
		wait(15)
		PowerComboCD.Value = false
	end))
end

Any kind of help would be appreciated.

1 Like

Are you trying to make it work for a specific player and only them and not work for others?

It works for all players, the only issue is that it grabs multiple enemies. Every player in the game can use that move, but it’s just that it bugs when you grab multiple enemies.

Im not much of a scripter but I think if you tag the closest character of the enemy that should fix your problem of hitting multiple enemies?

Yeah, I have no idea how the “tag” thing works. Like I said, I’m just a beginner coder.

1 Like

This is how you tag an enemy by gettings its humanoid

TagHumanoid(EnemiesHumanoid, EnemyCharacter)

and untagging is pretty easy

UntagHumanoid(EnemiesHumanoid)

I don’t know if this will help but yeah

I have no idea where to place them, but thanks for the info

function GetClosestCharacter(plr)
	local root = plr.Character.HumanoidRootPart
	local closest
	for _, v in pairs(game.Players:GetChildren()) do
		if v ~= plr then
			if closest then
				if (root.Position - v.Character.HumanoidRootPart.Position).Magnitude < (root.Position - closest.Position).Magnitude then
					closest = v.Character.HumanoidRootPart
				end
			else
				closest = v.Character.HumanoidRootPart
			end
		end
	end
	return closest.Parent
end

Not the best way but should work.