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

Why is my character appearance script not working?

Asked by 5 years ago
Edited 5 years ago

I'm trying to create a script that automatically changes the player's appearance on spawn.

This is my code so far for changing the shirt:

wait(5)
local playerModel = game.Players.LocalPlayer.Character

local shirt = playerModel:FindFirstChild("Shirt")
if shirt then shirt:Destroy() end
local newshirt = Instance.new("Shirt")
newshirt.Name = "Shirt"
newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=144076358"
newshirt.Parent = playerModel

Except that this doesn't work. The old shirt is deleted and the new shirt is placed successfully in the player model, but the new shirt doesn't show up. The player just has no shirt.

I have also tried the alternative

wait(5)
local player = game.Players.LocalPlayer
local playerModel = player.Character
player:ClearCharacterAppearance()

local newshirt = Instance.new("Shirt")
newshirt.Name = "Shirt"
newshirt.ShirtTemplate = "http://www.roblox.com/asset/?id=144076358"
newshirt.Parent = playerModel

This just leaves the player naked. The new shirt is still correctly placed in the model though!

I've spent hours trying different methods and researching this problem, like cloning the new shirt into the player model, but nothing has worked. I even found threads with this problem on this site, but those were old and also didn't work.

BTW, the wait() is just a placeholder for the code that waits until the player is fully loaded. I also own the shirt, so owning the shirt doesn't seem to be the problem.

Free model morphs do work, and their code seems to be almost the exact same, but for some reason mine doesn't work.

0
Don't use a wait() at the top of the script. It's bad practice. Use WaitForChild to load other objects and the CharacterAdded event to wait for the character. And I think the shirt must be yours. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

I don't know why yours wasn't working, I couldn't completely figure it out. However, there is an alternative solution, using InsertService.

However, the client can't load in assets, so you'd have to use a server script.

game:GetService('Players').PlayerAdded:Connect(function(plr) -- playerAdded event
    plr.CharacterAdded:Connect(function(char) -- characterAdded event
        wait(1) -- necessary as character finished loading after clearcharacterappearance so it didn't clear the character's appearance
        plr:ClearCharacterAppearance()
        local assetId = 144076358-- Id of the shirt you want
        local ok = game:GetService("InsertService"):LoadAsset(assetId) -- loads asset
        ok.Parent = char -- parent asset (shirt)
        ok.Shirt.Parent = char -- parent asset (shirt)
        ok:Destroy() -- Destroys left over model from insert service
    end)
end)

If you NEED to do this from a LocalScript, then use a RemoteEvent. If you're not familiar with those, let me know, and good luck!

0
This worked, thanks! XephyrHasNet 7 — 5y
0
No problem MythicalShade 420 — 5y
Ad

Answer this question