Advertisement
KashTheKingYT

If Statements/Debounce/Methods

Jan 3rd, 2023
1,213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. local part = script.Parent --Script's Parent
  2. local debounce = false --Boolean
  3.  
  4. function run(hitPart) --Function that runs when the part is touched
  5.     --Hitpart is the part that touched the part
  6.     local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
  7.     --The humanoid is the character's humanoid that has health/other humanoid properties
  8.    
  9.     if not debounce and humanoid then --We check if debounce is false and if there is a humanoid, if there is we run the function
  10.         debounce = true --Set debounce to true
  11.         humanoid:TakeDamage(15) --The humanoid takes damage
  12.         wait(2) --We wait 2 seconds
  13.         debounce = false --Set debounce to false
  14.     elseif debounce == true then --If debounce is true then print the debounce's value (true)
  15.         print(debounce)
  16.     end
  17. end
  18.  
  19. local connection = part.Touched:Connect(run) --Connects the part.Touched event to our run function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement