Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

Do this:

for i = 1, 4 do
wait(5)
Attack()
end

7 comments

3

THANK YOU!!!!

3

Does shortening your code make servers less laggy?

3

Probably not. Atleast I don't think so.

3

So I searched it up, it doesn't really change anything, but thanks for the help.

3

Also, I've seen for i,v in pairs a lot, does it do something similar?

3

Hope that explains it.

This discussion is preserved as it was. New answers, comments, and votes are closed.