Hi, I’m trying to make a button that can pause and resume physics. When I press the button the physics pause correctly, but then it does not resume.
local lastState = {}
local function TogglePhysics(Pause: boolean)
if Pause then
for i, instance in pairs(workspace:GetDescendants()) do
if instance:IsA("BasePart") and not instance:IsA("Terrain") then
lastState[i] = instance.Anchored
instance.Anchored = true
end
end
elseif not Pause then
for i, instance in pairs(workspace:GetDescendants()) do
if instance:IsA("BasePart") and not instance:IsA("Terrain") then
if lastState[i] then
instance.Anchored = lastState[i]
end
end
end
table.clear(lastState)
end
end