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

Will this unanchor all parts in a model?

I am trying to get something to spawn in a correct place, currently is spawns too low down as the position script kicks in too late. My solution is to keep it anchored, then unanchor it after 1 second which is enough time. This script is supposed to unanchor it but it doesn't, have I made a mistake?

wait(1)

for i,v in pairs(script.Parent:GetChildren())do
	v.Anchored = false
end

2 comments

0

ServerScript not Local.

0

It is a normal script located in the model

1 answer

✓ Accepted answer

There's a few things I'd change regarding this. First, not all Instances have a .Anchored property, and as a result, it's best to make sure it exists by running the code only on BaseParts or UnionOperations. Additionally, I'd be extra cautious and go with :GetDescendants() to get objects within folders within the model.

for _,v in pairs(script.Parent:GetDescendants()) do
	if v:IsA("BasePart") or v:IsA("UnionOperation") then
		v.Anchored = false
	end
end

By doing this, we actually remove any possible erroring that would have occured through setting .Anchored on an object like a script, while ensuring every part, both unionoperation and basepart, are unanchored.

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