#Debounce
Debounce is a commonly used feature which makes the script wait a certain amount of timew which can then fire your code;
If we use the most commonly used; "Touched Event Line", and add debounce you will realise it does not lag.
local PartName = "Part"
local db = false
workspace[PartName].Touched:Connect(function()
if not db then
db = true
print("I was touched")
wait(5)
db = false
end
end)
This will wait five seconds before firing the same action;
#Long Run-Lag
If you go in the dev-console; F9, then go to memory and press UntrackedMemory. UntrackedMemory, can cause a lot of lag, and many developers suffer from it
What causes UntrackedMemory?
This is a scale from worst to least;
1 - Connections
2 - While Loops
3 - Other repetitive stuff
4 -
5 -
6 -
Bad scripts example;
Connections;
script.Parent.Touched:Connect(function()
print("Hi")
end)
Loops;
while true do
wait()
print("HI")
Every-time a connection occurs, it goes directly into the UntrackedMemory folder.
How to fix and good scripts
Connections;
script.Parent.Touched:Connect(function()
print("Hi")
script.Parent.Touched:Disconnect()
Loops;
while true do
wait()
print("Hello")
break
2 comments
Doesn't really explain anything at all :/
Why did you answer an already explained question? Also it clearly reads "Wait's 5 seconds before you can use it again" and he understood. - he clearly isn't that much of a newbie in the scripting community do not insult his intelligence indirectly.