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

HELP! My Simple Punching Script Is STORING hits!!! PLZ help me!?

here is my "Simple" punching script. When fired the player does the animation

and it makes it when the left-hand is touched and finds a humanoid it damages it

but when fired multiple times it stores hits like when I'm not punching and bumping into the dummy, it damages it even though I'm not punching!!!!!!!!!!!!!

local Remote = game.ReplicatedStorage.PunchEvent

local found = false
Remote.OnServerEvent:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:wait()
	
	local rarm = char.LeftLowerArm
	
	
	
	rarm.Touched:Connect(function(hit)
		if hit and hit.Parent:FindFirstChild("Humanoid") then
			if found == false then
				found = true
		
		
			hit.Parent.Humanoid:TakeDamage(12)
			wait(1.5)
			found = false
		
			
end
		end
	end)
	
	
	
	
	
	
	
	
	

end)






2 comments

0

help me

0

Use debounce...

2 answers

#Debounce.

You could be using debounce, this way people will only be able to do a certain action on a specific amount of time.

Debounce is structured with booleans, and in your case you would have to do the following:

  • Define a true boolean.

  • Add an if statement which will return nil if the previous boolean hasn't met thetrue condition.

  • Make the previous boolean false.

  • Wait for a specific time.

  • Make it true again.

In your case, make a debounce for when the punchEvent is fired.

3 comments

0

a debounce doesnt need to be a boolean too

0

ok

1

@Expodo1234ALT It doesn't need to be, but usually is and it's better practice to define them as booleans.

if anim.IsPlaying then damageON = true else damageON = false end

3 comments

0

what is this

0

When the punch is clicked the animation plays hence only deal damage while the punch has been clicked and not when they are walking without clicking

0

Use a code block.

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