Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Variable for all anchored&not parts in workspace. [?]

Asked by 5 years ago

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)--

2 answers

Log in to vote
1
Answered by 5 years ago

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.

0
ohh lol thanks DemonEyee 55 — 5y
Ad
Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
5 years ago

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

Answer this question