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
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
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
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
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
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.
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.