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

[SOLVED]How to have a loop go over something a certain amount of time?

Asked by 6 years ago
Edited 6 years ago

So I only want my function to happen 4 times and I currently have a debounce which works fine but isn't there a way to shorten this?

My code:

debounce = true
times = 0

while debounce do
times = times + 1
if times <= 4 then
wait(5)
Attack()
else
debounce = false
end
end

Note: This code works fine, it's just I feel like theres an easier, shorter way to do this.

1 answer

Log in to vote
5
Answered by 6 years ago

Do this:

for i = 1, 4 do
wait(5)
Attack()
end
3
THANK YOU!!!! Tkanimations 85 — 6y
3
Does shortening your code make servers less laggy? Tkanimations 85 — 6y
3
Probably not. Atleast I don't think so. titaneagle 0 — 6y
3
So I searched it up, it doesn't really change anything, but thanks for the help. Tkanimations 85 — 6y
View all comments (3 more)
3
Also, I've seen for i,v in pairs a lot, does it do something similar? Tkanimations 85 — 6y
3
Hope that explains it. titaneagle 0 — 6y
Ad

Answer this question