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)
Clearly the first one...
The second one won't work
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.