Hitting a player applies the same effect to me

Hey guys it’s agKing here and today I have a problem with hitting a player so when I KO a player in Roblox it makes the ragdoll effect applies to me and that’s a very annoying issue so here’s the code of the effect

Events.ThrowPunch.OnServerEvent:Connect(function(player)
	if player then
		local character = player.Character
		local humanoid = character:FindFirstChild("Humanoid")
		local rootPart = character:FindFirstChild("HumanoidRootPart")
		local Head = character:FindFirstChild("Head")
		local RightLowerArm = character:FindFirstChild("RightLowerArm")
		local LeftLowerArm = character:FindFirstChild("LeftLowerArm")

		RightLowerArm.Touched:Connect(function(hit)
			local playerTouched = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			if playerTouched and playerTouched ~= player then

				local character = playerTouched.Character
				local humanoid = character:FindFirstChild("Humanoid")
				local rootPart = character:FindFirstChild("HumanoidRootPart")
				
				if humanoid and rootPart then
					RagdollJoints:SetupJoints(character, humanoid)
					local function DoRagdoll()
						humanoid.AutoRotate = false 

						for _, v in pairs(character:GetDescendants()) do
							if v:IsA("Motor6D") and v.Name ~= "Waist" and v.Name ~= "Root" then
								v.Enabled = false
							end
						end

						if humanoid.RigType == Enum.HumanoidRigType.R15 then
							for _, part in pairs(character:GetChildren()) do
								if part:IsA("BasePart") then
									part.CanCollide = true
								end
							end
						end


						force = Instance.new("BodyVelocity")
						force.MaxForce = Vector3.new(100000, 100000, 100000)  -- Max force
						force.Velocity = Vector3.new(0, -5, 0)  -- Apply downward force
						force.Parent = rootPart

						game:GetService("Debris"):AddItem(force, 4)

						wait(4)

						for i, v in pairs(character:GetDescendants()) do
							if v:IsA("Motor6D") then
								v.Enabled = true
							end
						end



						humanoid.AutoRotate = true
						humanoid:ChangeState(Enum.HumanoidStateType.Physics)




					end

					DoRagdoll()

				end

			end
		end)
		
		LeftLowerArm.Touched:Connect(function(hit)
			local playerTouched = game.Players:GetPlayerFromCharacter(hit.Parent)

			if playerTouched and playerTouched ~= player then

				local character = playerTouched.Character
				local humanoid = character:FindFirstChild("Humanoid")
				local rootPart = character:FindFirstChild("HumanoidRootPart")
				
				if humanoid and rootPart then
					RagdollJoints:SetupJoints(character, humanoid)
					local function DoRagdoll()
						humanoid.AutoRotate = false  

						for _, v in pairs(character:GetDescendants()) do
							if v:IsA("Motor6D") and v.Name ~= "Waist" and v.Name ~= "Root" then
								v.Enabled = false
							end
						end

						if humanoid.RigType == Enum.HumanoidRigType.R15 then
							for _, part in pairs(character:GetChildren()) do
								if part:IsA("BasePart") then
									part.CanCollide = true
								end
							end
						end


						force = Instance.new("BodyVelocity")
						force.MaxForce = Vector3.new(100000, 100000, 100000)  -- Max force
						force.Velocity = Vector3.new(0, -5, 0)  -- Apply downward force
						force.Parent = rootPart

						game:GetService("Debris"):AddItem(force, 4)

						wait(4)

						for i, v in pairs(character:GetDescendants()) do
							if v:IsA("Motor6D") then
								v.Enabled = true
							end
						end

						humanoid.AutoRotate = true
						humanoid:ChangeState(Enum.HumanoidStateType.Physics)
					end

					DoRagdoll()

				end
			end
		end)
		
	end
end)

I tried using Connection = on the touched event but this made the effect stop working I think the issue lies that event if the event hasn’t triggered on the server side such as LocalPlayer clicked to land a hit on a player the .Touched event still is getting trigger in the remote event tho the RemoteEvent from the other player haven’t executed the LowerArm.Touched event detect that whatever a touch has been made the player should ragdoll too which is not normal is there an issue to this problem ?

1 Like

try replacing it with this.

if playerTouched and playerTouched.Name ~= player.Name then

Let’s see I’ll try this line of code

1 Like

Yeah my code stopped working now the opponent player doesn’t get KOed anymore. Update I put an additionnal end to both statements my bad

Update : Nope still the same issue

I tried this line and still didn’t work

if playerTouched and playerTouched.Name ~= player.Name and isPunching then 

can you print the playerTouched and the player name, get back to me when you did.

I found a solution that worked man here’s the entire code

Events.ThrowPunch.OnServerEvent:Connect(function(player, throwHit)
	if player then
		local character = player.Character
		local RightLowerArm = character:FindFirstChild("RightLowerArm")
		local LeftLowerArm = character:FindFirstChild("LeftLowerArm")

		-- Fonction pour gérer les coups de poing
		local function handleHit(arm)
			return arm.Touched:Connect(function(hit)
				if isPunching then -- Vérifie si le punch est actif
					local playerTouched = game.Players:GetPlayerFromCharacter(hit.Parent)
					if playerTouched and playerTouched ~= player then
						local targetCharacter = playerTouched.Character
						local targetHumanoid = targetCharacter:FindFirstChild("Humanoid")
						local targetRootPart = targetCharacter:FindFirstChild("HumanoidRootPart")

						if targetHumanoid and targetRootPart then
							-- Application du ragdoll
							RagdollJoints:SetupJoints(targetCharacter, targetHumanoid)

							local function DoRagdoll()
								targetHumanoid.AutoRotate = false
								for _, motor in pairs(targetCharacter:GetDescendants()) do
									if motor:IsA("Motor6D") and motor.Name ~= "Waist" and motor.Name ~= "Root" then
										motor.Enabled = false
									end
								end

								if targetHumanoid.RigType == Enum.HumanoidRigType.R15 then
									for _, part in pairs(targetCharacter:GetChildren()) do
										if part:IsA("BasePart") then
											part.CanCollide = true
										end
									end
								end

								local force = Instance.new("BodyVelocity")
								force.MaxForce = Vector3.new(100000, 100000, 100000)
								force.Velocity = Vector3.new(0, -5, 0)
								force.Parent = targetRootPart
								game:GetService("Debris"):AddItem(force, 4)

								task.delay(4, function()
									for _, motor in pairs(targetCharacter:GetDescendants()) do
										if motor:IsA("Motor6D") then
											motor.Enabled = true
										end
									end
									targetHumanoid.AutoRotate = true
									targetHumanoid:ChangeState(Enum.HumanoidStateType.Physics)
								end)
							end

							DoRagdoll()
						end
					end
				end
			end)
		end

		-- Connecter les événements pour les deux bras
		local RightHandConnection = handleHit(RightLowerArm)
		local LeftHandConnection = handleHit(LeftLowerArm)

		-- Activation du punch
		isPunching = true
		task.delay(0.5, function() -- Durée pendant laquelle le punch est actif
			isPunching = false
			if RightHandConnection then
				RightHandConnection:Disconnect()
				RightHandConnection = nil
			end
			if LeftHandConnection then
				LeftHandConnection:Disconnect()
				LeftHandConnection = nil
			end
		end)
	end
end)
1 Like