Hello, in my game I have lots of situations in which I can choose to use a while loop or a repeat loop (and in some case a for i,v loop). But I don’t know which one is better, especially for performance (many loops are in the server).
Here is an exemple of for i,v loop, then i’ll show an exemple of repeat loop for the same tasks
rs.ClientEvents.MobileGearsTrop.OnServerEvent:Connect(function(plr)
if #plr.Tout.Gears:GetChildren() <= 7 then plr.Tout.ExploitCheck.Value += 1 if plr.Tout.ExploitCheck.Value >5 then plr:Kick('Stop Exploit please') end return end
for i,v in plr.Tout.Gears:GetChildren() do
v:Destroy()
if #plr.Tout.Gears:GetChildren() <= 7 then
break
end
task.wait()
end
end)
So in this for i,v loop i detect the amount of children , if the amount is over 7 then i destroy some children untl the amount of children is <=7
Now let’s see the same script with a repeat
rs.ClientEvents.MobileGearsTrop.OnServerEvent:Connect(function(plr)
if #plr.Tout.Gears:GetChildren() <= 7 then plr.Tout.ExploitCheck.Value += 1 if plr.Tout.ExploitCheck.Value >5 then plr:Kick('Stop Exploit please') end return end
repeat
plr.Tout.Gears:FindFirstChildOfClass('BoolValue'):Destroy()
task.wait()
until #plr.Tout.Gears:GetChildren() <= 7
end)
i could do the same with a while loop but you understand what i mean. Could you tell me which one should i use and Overall which one is the better for performance ? Any help advice is welcolme and apprecied ! Thanks