Im trying to make a basic for i v pair script, I wanna unachor all the parts of a model at the same time using for i v pair loops since im still trying to learn it.
‘local Parts = {game.Workspace.Model:GetChildren()}
for i , v in pairs(Parts) do
v.Anchored = false
end’
You don’t need to cover game.Workspace.Model:GetChildren() in brackets since the function itself return the children instances in a table so you don’t have to.
local Parts = game.Workspace.Model:GetChildren()
for i , v in pairs(Parts) do
v.Anchored = false
end’
You should disregard this post and the post I’m replying to, because unanchoring all the parts would be instant anyways (and spawning new threads would take just as long, if not longer)
Old post
Note: This isn’t true. spawn doesn’t yield the thread its called in. Ignore this post.
If the model has a lot of parts, this could actually take quite a while because spawn() has a wait() built into it.
If you need to unanchor every part at the exact same time, you should use the coroutine library instead.
local Parts = game.Workspace.Model:GetChildren()
for _,v in pairs(Parts) do
coroutine.wrap(function()
v.Anchored = false
end)() -- coroutine.wrap() returns a function, these extra parenthesis call the returned function
end