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

Items reset when i spawn. how can i keep the items morph when reset?

Asked by 4 years ago
local debounce = true

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local HumanoidDescription = character:WaitForChild("Humanoid"):WaitForChild("HumanoidDescription")
        local ID = 64082730 -- The Rainbow Shaggy ID.
        if character.Name == "Playername" and debounce == true then -- Replace "Playername" with the name you want to spawn with the Hair.
            debounce = false
            wait(0.5) -- Keep the wait, as I tested this without the wait it was just an infinite loading screen.
            HumanoidDescription.HairAccessory = ID
            player:LoadCharacterWithHumanoidDescription(HumanoidDescription)
        end
    end)
end)

When i reset the shaggy morph dissapears how can i make it so it stays when i reset charactter aswell?

1 answer

Log in to vote
0
Answered by
Luathron 185
4 years ago
local Players = game:GetService("Players")
local InsertService = game:GetService("InsertService")

function getAccessoryType(accessoryInstance)
    local attachment = accessoryInstance.Handle:FindFirstChildOfClass("Attachment")
    local accessoryType = attachment.Name:match("(.+)Attachment")
    return accessoryType
end

local HairID = 64082730
Players.PlayerAdded:Connect(function(Player)
    if Player.Name == "forsakern" then
        Player.CharacterAppearanceLoaded:Connect(function(Character)
            local Humanoid = Character:FindFirstChildOfClass("Humanoid")
            if Humanoid then
                local success, model = pcall(InsertService.LoadAsset, InsertService, HairID)
                if success then
                    for _, v in pairs(Humanoid:GetAccessories()) do -- Removes existing hair
                        if getAccessoryType(v) == "Hair" then 
                            v:Destroy() 
                        end 
                    end
                    model.Parent = workspace
                    Humanoid:AddAccessory(model:GetChildren()[1])
                    model:Destroy()
                end
            end
        end)
    end
end)
0
OMG THANKYOU UR THE BEST!!! forsakern 12 — 4y
Ad

Answer this question