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

Part that does damage at a constant speed to you doing it inconstantly?

so im trying to create a part that when the player enters it does damage at a constant speed for an example im trying to do 25 damage every 5 seconds although it dosnt do 1 ever 5 it tries to squeeze in as meany times as possible in the time its active, heres my script

local Debounce = false
local function onTouch(hit)
	Debounce = true
	print(hit.Parent)
	hit.Parent.Humanoid:TakeDamage(25)
	wait(5)
	Debounce = false
end

script.Parent.Touched:connect(onTouch)

I merged two scripts that I found on YT together and this works but not in its intended way for any who does help; Thanks ;)

1 answer

✓ Accepted answer
local Debounce = false
local function onTouch(hit)
	if not Debounce then
   		Debounce = true
    		print(hit.Parent)
    		hit.Parent.Humanoid:TakeDamage(25)
    		wait(5)
    		Debounce = false
	end
end

script.Parent.Touched:connect(onTouch)

You need to use an if statement for debounce to work, or else the debounce will do nothing except changing its own value

5 comments

0

I tried it and I also tried messing around with it and it just seems to break the script

0

eh no, why would it break the script? e.e thats just how you use debounce, its most likely your "messing around" that breaks it, post what you have written now

0

im currently using the one you sent, my messing around was just moving things like the print(hit.Parent) to see if the local function still worked (which it did)

0

i updated the code a bit, try it again, also were there any error?

0

yeah thanks its working now but at first it didn't come up with an error

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