Scripting Skills 002: Le Debounçe

Well-come!

This is a new colour scheme!

For today's lesson, we will go over debounçe. Debounçe is a scripting mechanism that allows an event to only execute when it is not working already. You may be like, how do you do that in C#? Well, I will answer you: I don't know.

How-ever, I know about Lua events. I will give you an example of a script that prints the ID of your character. Then, it will check if you are an Age King. If you are not, then death to thee! If you are, then you are still alive, and you can keep going with your Rōbloxian fun time!

game.Workspace.Part.Touched:connect(function(h)

if h.Parent:findFirstChild('Humanoid') then

local char=h.Parent

local p=game.Players:playerFromCharacter(char)

print(p.userId)--In le output!

if p.userId<=game.CreatorId then--Checks if you are older than the place creator!

print('You can keep going with your Robloxian fun time!')

else

char.Humanoid.Health=0--Kills you if you are NOT an Age King!

end

end

end)

There, the script without debounçe! You know what'll happen when you have too many players at once touching le block? Well, we have the answer! IT all lies in debounçe! Now, we will show you the exact same thing, but we added a taste of D with a spice of E and B, deep-fried in a mixture of O and U, and finally covered in N-Ç-E spread!

d=false

game.Workspace.Part.Touched:connect(function(h)

if h.Parent:findFirstChild('Humanoid') and not d then--This line checks if 'd' is true.

d=true--THis line turns on 'd' so that when this executes while 'd' is true, it does not execute.

local char=h.Parent

local p=game.Players:playerFromCharacter(char)

print(p.userId)--In le output!

if p.userId<=game.CreatorId then--Checks if you are older than the place creator!

print('You can keep going with your Robloxian fun time!')

else

char.Humanoid.Health=0--Kills you if you are NOT an Age King!

end

d=false--This line removes debounce.

end

end)

So, what have we learnt? I learnt absolutely nothing, and so might have you! I am confusing in my lessons (all of them), so just give me a break! FINE, I will explain! The script first initiates variable 'd' to false. When the event is called (second line), the rest of the script executes, under 2 conditions. The first if whether the part's parent has a humanoid. If so, then it checks if 'd' is false, by using the not operator before it. After the if-statement, it switches 'd' to true, the executes the rest of the script. When the script is done executing, 'd' becomes false again. Note that 'd' was just one way you can name the variable for debounçe. That is just a common variable name used by scripters.

Have fun, Scriptadores!

Snapchat's son!

And don't forget, #0078D7!