[repost, please reply!] script not returning a print upon finding a child

im making a combat system for my game and i want the script to return the message “Blocked” if it finds an accessory in the target character called “Blocking”
i’ve tested this with my friends and with dummies, and the script doesnt seem to detect the Blocked accessory being there, even though it is there. here’s the code which is supposed to do this:

Requests.DamageHumanoid.Event:Connect(function(character, target, properties)
	if character:FindFirstChildWhichIsA("ForceField") or target:FindFirstChildWhichIsA("ForceField") then return end
	if target:FindFirstChild("Knocked") then return end
	
	print(character.Name .. " has just fired damage humanoid on ".. target.Name ..".")
	
	if properties.block then
		if (target.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Unit:Dot(target.HumanoidRootPart.CFrame.LookVector) >= 0.2 then
			for _,v in pairs(target:GetChildren()) do
				if v.Name == "Blocking" then
					v:Destroy()
				end
			end
		end
		
		if target:FindFirstChild("Blocking") then
			target.HumanoidRootPart["punch-block".. math.clamp(properties.combo, 1, 4) or 1]:Play()
			
			return "blocked"
		end
	end

the part in specific in this function that is causing an issue is the “if” statement at the bottom.
i would really appreciate some help as i dont really know what to do… everything else in the system works just fine though

The issue you’re facing might be related to how you are checking for the “Blocking” accessory in the target character. Let’s modify your code to address this problem:

Requests.DamageHumanoid.Event:Connect(function(character, target, properties)
	if character:FindFirstChildWhichIsA("ForceField") or target:FindFirstChildWhichIsA("ForceField") then return end
	if target:FindFirstChild("Knocked") then return end
	
	print(character.Name .. " has just fired damage humanoid on ".. target.Name ..".")
	
	if properties.block then
		local blockingAccessory = target:FindFirstChild("Blocking")
		
		if blockingAccessory then
			-- Assuming "punch-block1" to "punch-block4" are Animation objects in the HumanoidRootPart
			local comboAnimationName = "punch-block" .. math.clamp(properties.combo or 1, 1, 4)
			local comboAnimation = target.HumanoidRootPart:FindFirstChild(comboAnimationName)
			
			if comboAnimation and comboAnimation:IsA("Animation") then
				comboAnimation:Play()
				return "Blocked"
			end
		end
	end
end)

If there’s any further Issues, please do let me know.

1 Like

thanks, but i probably should have clarified beforehand that the punch-block1 to punch-block4 objects are actually sounds that play accordingly to what punch they got hit by while they were blocking.

If you need an elaboration, the issue was order of operations. The or operator has the lowest priority of the bunch so it will happen last. You can also fix this line by just adding parentheses to change the precedence.

that’s just the sound effects, the actual issue in the script is that when player 1 attacks player 2 which is blocking, the damage goes through anyway, and subsequently the blocking punch sound effects don’t play either.

id appreciate some help plz ion really know what to do rn

please help i kind of feel like im shouting into the abyss rn i need help i do not have any idea what to do please help