DarstrialB
(DarstrialB)
November 16, 2024, 3:23am
#1
Hello everyone.
I am working on a part spawning game, and a feature in question is spawning more than one part. How can I prevent players from spamming the button (that spawns the objects) until the loop is done?
This is an example:
for i = 1, 5 do
spawnPart()
end
Is there any way to check if i = 5? is it just:
if i = 5 then
end
Thank you.
2 Likes
Colinchannz
(EveryonesIdol_Carina)
November 16, 2024, 3:47am
#2
You can try a debounce check or similar. I will assume you have code that triggers that loop already.
For instance:
local SpawningParts = false
if SpawningParts == false then
SpawningParts = true
for i = 1, 5 do
-- code here
end
SpawningParts = false
end
Traditionally, “SpawningParts” would be called “debounce” but I personally like relating variable names to its function.
And to answer your second question, the loop will end once “i” equals 5