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

Help with deciding what script is better used?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Which is a better way of creating this script that anchors all parts in character?

FIRST SCRIPT:

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(char)
        for i, v in pairs (char:GetChildren()) do
            if v:IsA("Part") then
                v.Anchored = true
            end
        end
    end)
end)]

SECOND SCRIPT:

game.Players.PlayerAdded:connect(function(Player)
    local Char = game.Workspace[Player.Name]
    for i, v in pairs (Char:GetChildren()) do
        if v:IsA("Part") then
            v.Anchored = true
        end
    end
end)

0
You might want to use BasePart instead of Part. GoldenPhysics 474 — 7y
0
What is difference? FiredDusk 1466 — 7y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

Clearly the first one...


The second one won't work

  • ...when the player's character takes time to load (hint: it always does)
  • ...when the player's character resets (hint: you can't disable the Reset button in the settings menu)

Even if you were using the second one, you should use player.Character, (and workspace not game.Workspace) .

If you only want it to happen the first spawn, you can use

local char = player.Character or player.CharacterAdded:wait()

which is a bit like connecting to the event, but only caring about the first one.

0
"...when the player's character resets (hint: you can't disable the Reset button in the settings menu)" by changing the name of the character's humanoid the button breaks which technically disables it. UniversalDreams 205 — 7y
0
I need to remember that line of code. It can be very helpful, I think. GoldenPhysics 474 — 7y
Ad

Answer this question