I’m attempting to make my script to print out all of the children in the character’s model, but it just prints out HumanoidRootPart - what’s the concurrent issue here?
Edit: I’ve updated the script that it seems to be broken on:
local rep = game.ReplicatedStorage
local characters = rep.Characters
local character = {characters.Darisel, characters.Jo, characters.Kennedy, characters.Rabish}
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
for _, i in pairs(char:GetChildren()) do
if i:IsA("Accessory") then
i:Destroy()
end
local randomCharacter = character[math.random(1, #character)]
local cloneAccessories = randomCharacter.Accessories:Clone()
cloneAccessories.Parent = char
for _, c in pairs(cloneAccessories:GetChildren()) do
c.Anchored = false
end
if i:IsA("Shirt") then
i.ShirtTemplate = randomCharacter.Shirt.ShirtTemplate
else
local shirt = Instance.new("Shirt", char)
i.ShirtTemplate = randomCharacter.Shirt.ShirtTemplate
end
if i:IsA("Pants") then
i.PantsTemplate = randomCharacter.Pants.PantsTemplate
else
local pants = Instance.new("Pants", char)
i.PantsTemplate = randomCharacter.Pants.PantsTemplate
end
end
end)
end)
That’s strange. I did the code by its own, and it seems to function, but it doesn’t operate at all when I provide an entire script. Is there an issue with this script?
local rep = game.ReplicatedStorage
local characters = rep.Characters
local character = {characters.Darisel, characters.Jo, characters.Kennedy, characters.Rabish}
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
for _, i in pairs(char:GetChildren()) do
if i:IsA("Accessory") then
i:Destroy()
end
local randomCharacter = character[math.random(1, #character)]
local cloneAccessories = randomCharacter.Accessories:Clone()
cloneAccessories.Parent = char
for _, c in pairs(cloneAccessories:GetChildren()) do
c.Anchored = false
end
if i:IsA("Shirt") then
i.ShirtTemplate = randomCharacter.Shirt.ShirtTemplate
else
local shirt = Instance.new("Shirt", char)
i.ShirtTemplate = randomCharacter.Shirt.ShirtTemplate
end
if i:IsA("Pants") then
i.PantsTemplate = randomCharacter.Pants.PantsTemplate
else
local pants = Instance.new("Pants", char)
i.PantsTemplate = randomCharacter.Pants.PantsTemplate
end
end
end)
end)
If you’re running your code on the client, this would be the problem. When CharacterAdded is fired, not all parts have finished replicating from the server to the client, so the client won’t ‘see’ all of the parts. I got around this by making a module that returns a table containing all of the part names in a standard R15 rig, and I WaitForChild() on each part name.
The new Avatar load order might solve this problem as well when it comes out.