[2nd repost, please reply!] script not returning a print

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”

(just to clarify, the line which plays the punch-block sound effect doesnt seem to be an issue, and they are not animations, they’re sounds, thank you.)

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

your returning not printing, change the return to a print and then it should work?

alright, ill try that then thanks

doesnt seem to do anything, the enemy still takes damage and “blocked” isnt printed

oh i wasnt actually aware of how to use that, so ill go for it thanks

uh that ended up just stopping the entire combat system from even dealing damage, ragdolling or applying force so im guessing that probably isnt the way to go

I think that means the accessory isnt there

it is, i was checking
this is why im so confused, since even if it is there nothing happens.

You’ve said the last if statement doesn’t work, so try this to help understand why:

if properties.block then
local dot = (target.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Unit:Dot(target.HumanoidRootPart.CFrame.LookVector)
print(dot)
		if dot >= 0.2 then --destroys blocking if dot is too high
			for _,v in pairs(target:GetChildren()) do
				if v.Name == "Blocking" then
					v:Destroy()
				end
			end
		end
		-- search for blocking, but could be destroyed
print(target:FindFirstChild("Blocking"))
		if target:FindFirstChild("Blocking") then
			target.HumanoidRootPart["punch-block".. math.clamp(properties.combo, 1, 4) or 1]:Play()
			
			return "blocked"
		end
	end
1 Like

i tested it and it prints out a long coordinate, what is the purpose of dot?? sorry but im just confused getting my head around waht it is and how it correlates to checking an accessory

I’m not sure myself, but it’s in your code I just moved it to a local variable.
I assumed it was a technique to check the target player was facing the character so the block would work but my math isn’t great with this.
Either way, if this is triggering the destroy blocking loop then it will cause the next one to fail.

oh, im sort of following off of an open source resource to do some of the things in my combat system, but i intend for the block to be 360*, not checking what direction the person being attacked is facing.

i dont really know what to do still.
th blocking accessory isnt being destroyed however

Maybe you could comment it out see if it changes anything.
But if the second print finds the blocking accessory then, perhaps it’s this index,

target.HumanoidRootPart["punch-block".. math.clamp(properties.combo, 1, 4) or 1]:Play()

It’s indexing either [“punchblock…”] or [1]

i don’t think this is the issue as i tried removing the line to see if it changed the outcome and nothing changed, once again the script couldnt detect the blocking accessory and thus the enemy was still damaged

Ok, so basically I can’t find an issue with this script, so…
Where is “blocked” returned to?

the target?? i think i dont really know for sure im not that good at scripting

Hmmm, should have spotted it sooner. It’s a bindable event which can’t return anything.
You need to set it up as a bindable function to get a return value.

Request.DamageHumanoid.OnInvoke = function()
-- code
end

You may need to change the calling script as well to :Invoke instead of :Fire and change the event instance to a bindable function instance.
It might be worth posting the script which makes the call too to check the logic in there.

ill try changing it, then if not ill send you the client handling script.

hmm, i changed it to a bindablefunction and set it up accordingly using getinvoke and invoke, but the issue is still the same, with “Blocking” being present, but damage still going through.

i got it working, finally cuz my friend helped explained it to me (im a bit slow)