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

Unanchor every part in workspace?

So I'm making an anti-cheat system, but instead of kicking them, I'm gonna scare them and then change the skybox and play doom music, and then finally unanchoring the workspace (Local only, of course).

I've tried this:

local map = game.Workspace:GetChildren()
map.Anchored = false

Doesn't work. Help!

1 answer

✓ Accepted answer

Right. That's not how GetChildren() works. GetChildren returns a table. A table does NOT have any properties. only Values or Keys (Related to Dictionaries). So map.Anchored isn't a true value (it returns nil, basically). Because map.Anchored isn't defined. Lua thinks that Anchored is a key, which holds a value, which doesn't, so it returns nil. Here's how you can solve it.

local map = workspace:GetChildren() --same thing as game.Workspace except it's easier to type

for i, v in pairs(map) do --This loops through a table. i means index (or the number. It can also hold the keys (Again related to dictionaries.) v means value, and that's what we're gonna manipulate.
	if v:IsA("BasePart") then --This is just to check if it is a Base Part. Base Part means Wedges, Normal Parts, or Mesh Parts, etc.
		v.Anchored = false --This is what you wanted.
	end
end

3 comments

0

Thank you for explaining how it works too! Most people only show a solution. Thanks!

1

wouldn't it be smarter to use :GetDecendents() as that would mean it would also unanchor any part in the workspace, rather then just the parts with the workspace as their parent?

0

Yeah, that's true.

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