Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

5 comments

1

Oh man this indention. Please fix it.

2

punch better

0

get gud

0

oof tell that to my players rip

0

yea :p  it's their fault

1 answer

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.

4 comments

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!

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

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?

0

if my answer helped you can you please accept it? :P

This discussion is preserved as it was. New answers, comments, and votes are closed.