I'm trying to make a timestop script for my JJBA game, but every time I launch this script, the players character parts are left anchored.
Here's a simplified version of the code:
local anchor for _, v in pairs(workspace:GetDescendants()) do if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then anchor = v.Anchored end end for _, v in pairs(workspace:GetDescendants()) do if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then v.Anchored = true end end wait(5) for _, v in pairs(workspace:GetDescendants()) do if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then v.Anchored = anchor end end
--(The camera moves around because of the HumanoidRootPart, don't say anything about that, I just want to unanchor the character parts)--
Your loop in the first part is only getting the anchor value of the last brick it loops through as its just a normal variable. I assume the issue is that the last part is loops through is anchored so it then anchors everything in the last loop.
I would rewrite this to loop through the Character of each player instead of through all of workspace:
local players = game.Players local function anchor() local players = players:GetPlayers() for _, player in pairs(players) do local character = player.Character or player:WaitForChild("Character") for _, part in pairs(character:GetChildren()) do if part:IsA("BasePart") and part.Name ~= "HumanoidRootPart" then part.Anchored = not part.Anchored --Will change it from frozen/unfrozen/frozen/... end end end end