How would you be able to anchor/unanchor all object in a game without much lag?

I’m trying to make a script that basically freezes the game. This script will anchor/unanchor every part in the game accordingly. However, doing this will cause a lot of lag (since there are a lot of parts in the game)

Is there any alternative to this, or should I just not do this?

2 Likes

Anchoring all parts in game should not be laggy but un-anchoring will be. Are there parts in the game that are auto anchored so they dont need to be un-anchored and re anchored? or does every part need to be
un-anchored and re anchored?
if every part needs to be un-anchored and re anchored i would suggest not doing this.

1 Like

There are some parts (like buildings) that stay anchored. I only anchor the parts that were previously not anchored, then I insert them into a table where they then can be unanchored later

1 Like
for i, v in pairs(workspace:GetDescendants()) do
	if v:IsA("BasePart") or v:IsA("MeshPart") then
		v.Anchored = true -- can be false if wanted
	end
end

some rough code tyoed up, i suppose this could work for ALL objects

edit:
ok scratch that, make a table add names in it you wanna keep anchored or not, check if the item name is in the table (table.find(tbl, name)), if so then anchor or unanchor them

1 Like

You could use a for loop which loops through all parts in the game and anchors them
Ex:

for I,v in pairs(game.Workspace:GetChildren()) do
    if v:IsA("Part") then
        if v.Anchored = false then
              v.Anchored = true
        end
    end
end
1 Like

This is what I’m currently doing, which just makes it lag a lot when you unanchor. I was thinking of a substitute to get the anchor effect but I currently know none

1 Like

then just add task.wait() so it doesnt do everything at once, i guess?

1 Like

I also tried this, but since there are just so many parts in the game, it basically just takes like 5-9 seconds to unanchor all parts

1 Like

I would not recommend doing this. i would find a substitute.

Yeah, I thought of setting gravity to 0 (it didn’t work obviously) and other stuff but I don’t really have much knowledge of the physics system in Roblox so nothing I’ve tried worked

1 Like
local Workspace = workspace

local function AnchoredToggle(Boolean)
	local BaseParts = {}

	for _, Descendant in ipairs(Workspace:GetDescendants()) do
		if Descendant:IsA("BasePart") then table.insert(BaseParts, Descendant) end
	end

	for Index, BasePart in ipairs(BaseParts) do
		if Index % 100 == 0 then task.wait() end
		BasePart.Anchored = Boolean
	end
end