Stuck on loading screen when trying to make custom rig script

Hello! I’m currently trying to make a script that turns the player character to a custom rig while keeping the same accessories.

Whenever I try to press play or play here in Roblox Studio it gets stuck on the default Roblox loading screen, I’ve also tried accessing the game from the actual game link on the Roblox website but it still gets stuck on the loading screen.

Here is the current script:

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local rig = ServerStorage.CustomStarterRig

Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAppearanceLoaded:Connect(function(character)
        local rigClone = rig:Clone()
        local spawnPos = character:GetPrimaryPartCFrame()

        for _, instance in pairs(character:GetChildren()) do
            if instance:IsA("Accessory") then
                instance:Clone().Parent = clone
            end
        end 

        plr.Character:Destroy()
        plr.Character = rigClone
        rigClone:SetPrimaryPartCFrame(spawnPos)
    end)
end)

However, when I remove this code segment:

        plr.Character:Destroy()
        plr.Character = rigClone
        rigClone:SetPrimaryPartCFrame(spawnPos)

And press play it doesn’t get stuck on the loading screen anymore but if I remove that segment of code entirely it wouldn’t really do what it’s intended to do.
Any ideas?

“clone” here should be “rigClone”.

1 Like