When and how would you use a for loop in a script?
✓ ANSWER ACCEPTED
How would you use a for loop?
1 answer
✓ Accepted answer
You could use this for(sort of) smooth part interpolation.
for q=1,360 do --do 360 times
part.CFrame = part.CFrame*CFrame.Angles(math.rad(1),0,0) --will pin it around smooooothly
end
You could use it for fading.
part = game.Workspace.Baseplate
for q=0,1,.01 do
part.Transparency = q
end
And like Sporkyz said, search through tables, and repeat a certain number of times.
Sporkyz actually deleted his answer though.
You could use it for random map generation. Or to do something to all the players in game or parts in a model.
for q=1,#game.Players:GetChildren() do
local player = game.Players:GetChildren()[q]
player:Kick("Bwahahahaha! I hackified you!") --good to kick all the players
end
for i,v in pairs(game.Workspace.Model:GetChildren()) do wait()
v.Color = Color3.new(math.random(0,255)/255,math.random(0,255)/255,math.random(0,255)/255)
--color all the parts randomly
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
