I don’t know what update changed things last night, but when parenting a shirt/pants into the character as they spawn, the shirt/pants immediately destroy themselves.
Below is a simple repro script:
local players = game.Players
function giveClothes(id, type, parent)
local cloth
if type == 1 then
cloth = Instance.new("Shirt",parent)
cloth.ShirtTemplate = id
elseif type == 2 then
cloth = Instance.new("Pants",parent)
cloth.PantsTemplate = id
end
return cloth
end
players.PlayerAdded:connect(function(ply)
ply.CharacterAdded:connect(function(char)
local shirt = giveClothes("http://www.roblox.com/asset/?id=132601069",1,char)
local pants = giveClothes("http://www.roblox.com/asset/?id=132601229",2,char)
end)
end)
I’ve noticed that adding a wait(1+ seconds) helps with stopping the clothes from being destroyed, but it’s not consistent and doesn’t work all the time.
I think it is because the character may not be finished loading, and because of this will overwrite the shirt you put with the shirt there should have been. Try using
CharacterAppearanceLoaded ( Model character )
rather than CharacterAdded
should look something like this,
ply.CharacterAppearanceLoaded:connect(function(char)
local shirt = giveClothes("http://www.roblox.com/asset/?id=132601069",1,char)
local pants = giveClothes("http://www.roblox.com/asset/?id=132601229",2,char)
end)
I’ve never actually used that function before, because most of the time I spawn in my own character, but you can go ahead and try it.
Alright, so I changed the repro script to use CharacterAppearanceLoaded, and it seems to work fine. However, when I changed the actual script where I’m using this, the same thing happens, only with a slight delay. The new shirt+pants are added after the character’s appearance loads(expected) but then the new shirt+pants get destroyed after half a second.
Using CharacterAppearanceLoaded fixed the issue. Probably a much better solution than using CharacterAdded. Would this still be considered a “bug”?