local shirtID = script:GetAttribute("ShirtID")
local pantsID = script:GetAttribute("PantsID")
local function onJoin(plr) -- player joins
print("plr joined")
plr.CharacterAdded:Connect(function(char) -- character loads
char:WaitForChild("Shirt").ShirtTemplate = shirtID
char:WaitForChild("Pants").PantsTemplate = pantsID
end)
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
coroutine.wrap(onJoin)(plr)
end)
I’m trying to apply a different shirt and pants to each players’ character. When I check in the explorer, the ID is set for both the pants and shirt but it doesn’t actually update visually; it only does so when I re-enter it manually. How do I fix this? There were no errors.
Well if none of that works you can always just use InsertService
LoadAsset function should be sufficient if you just pass through the ID
local InsertService = game:GetService("InsertService")
function LoadAsset(Id)
local Success, Result = pcall(function()
return InsertService:LoadAsset(Id)
end)
if Success then
local Asset = Result:GetChildren()[1] --It comes in a model so just get the first child which should be the shirt or pants
return Asset
else
warn(Result)
return "Failed" --Consider retrying
end
end
local Result = LoadAsset(ShirtId)
if typeof(Result) == "string" then
--Consider retrying
else
--It successfuly loaded do what you want with it!
end
local shirtID = script:GetAttribute("ShirtID")
local pantsID = script:GetAttribute("PantsID")
local Character = nil
game.Players.PlayerAdded:Connect(function(Player))
if Player.Character ~= nil then
Character = Player.Character
if Character ~= nil and Character:FindFirstChildOfClass("Shirt") and Character:FindFirstChildOfClass("Pants") then
local Shirt = Character.Shirt
local Pants = Character.Pants
Shirt.ShirtTemplate = ShirtID
Pants.PantsTemplace = PantsID
end
end
end)
I know this is already solved and all, but I’m pretty sure this happened because the roblox character loads before the shirt and pants are applied by script, and sometimes scripts can beat the default scripts in efficiency, but it’s so minuscule that it’s hard to see.
So instead of using plr.CharacterAdded
Use Player.CharacterApperanceLoaded, this event will prevent that, if you want to do it in less lines.