Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with my punch script that is causing it to miss so much?

Asked by 5 years ago

So basically heres how it works, it invokes the server when you press the punch key, and the server side script clones a dmg script inside it into the players Left hand,

J = false
            local PlayerWhoPunched = script.Parent.Parent.Name
local LHand = script.Parent
    local hurt = script.DMG
        LHand.Touched:connect(function(Part)
            if J == false then 
        J = true
        if Part.Parent:FindFirstChild("Humanoid") then
                    local Human = Part.Parent:FindFirstChild("Humanoid")
Human.Health = Human.Health - hurt.Value
        end
            end
        end)

Now it works perfectly sometimes but other times it just does not register the hit, is this because I do not have the script that does the dmg itself disabled before its cloned? Or could it be because of my animation? Because I swear I have landed so many hits on the head just for them to not register

1
Oh man this indention. Please fix it. DinozCreates 1070 — 5y
2
punch better User#24403 69 — 5y
0
get gud theking48989987 2147 — 5y
0
oof tell that to my players rip XX_Scripta 11 — 5y
0
yea :p  it's their fault theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by
IDKBlox 349 Moderation Voter
5 years ago

Well using part.Parent:FindFirstChild('Humanoid')... A good thing you can do to check this is to print what part.Parent name is.

There is a possibility you're hitting an accoutrement (Hat, Wings, etc) or a Tool which would make its part.Parent the accoutrement or a tool. Therefore you would never find a Humanoid within it. (And if you do, it's probably not the 'Humanoid' you're looking for lol)

Not sure if this is the 'Best' solution but what I have done before is taken the part that's been hit and check for part.Parent:FindFirstChild('Humanoid') or part.Parent.Parent:FindFirstChild('Humanoid')

I'm sure there are many other ways (More efficient) but I've used this and it's worked for me. Give it a shot and let me know.

0
oof my bad I do have it print the part it hits but not the part.parent. I will try this out though Thanks! XX_Scripta 11 — 5y
0
Seems you are right, I am hitting the hats on the person, should I make them punch lower for the animation to help though (I will still the Part.parent.parent thing) As currently the animation aims for like your head and way top of your upper torso (All the accessory's are on your head)) XX_Scripta 11 — 5y
0
Well now that depends on you. Would you like it better if they punched lower? or do you want them to still punch where they are already? IDKBlox 349 — 5y
0
if my answer helped you can you please accept it? :P IDKBlox 349 — 5y
Ad

Answer this question