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

How can I make each part touched only once using debounce?

Asked by
MrHerkes 166
5 years ago
Edited 5 years ago

Let's say that I made a hitbox. Five parts are touching the hitbox. Each part will be touched only once. If the hitbox touches that part again, the code wouldn't run on it. Are there any efficient ways of doing that?

1 answer

Log in to vote
0
Answered by
lunatic5 409 Moderation Voter
5 years ago

You can have a variable for each part called, for example, "enabled". You can default the variables to true. In the Touched event, you can check if the variables are true using if statements. Then, inside of the if statements, after the rest of your code, set the variables to false. This way, the code will only run the first time the part is touched. Your code would look something like this:

local enabled = true

part.Touched:Connect(function()
    if enabled then
        --code
        enabled = false
    end
end)
Ad

Answer this question