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

How can I fix this morph that only works part of the time?

Asked by 4 years ago

I'm trying to create my own morphs and it works perfectly in a new studio window, but when I test it in an actual game, many of the parts are in the wrong place. How can I fix this? Here is my code:

script.Parent.Touched:Connect(function (hit)
    if hit.Parent.Humanoid and game.Players:GetPlayerFromCharacter(hit.Parent) then
        if hit.Parent:FindFirstChild("Chest") == nil then
            local chest = Instance.new("Model",hit.Parent)
            chest.Name = "Chest"
            local middle = script.Parent.Parent.Chest.Middle:Clone()
            middle.Parent = chest
            middle.Anchored = false
            for i,v in pairs(script.Parent.Parent.Chest:GetChildren()) do
                if v.Name ~= "Middle" then
                    local part = v:Clone()
                    part.Anchored = false
                    local weld = Instance.new("WeldConstraint",part)
                    weld.Part0 = middle
                    weld.Part1 = part
                    part.Parent = middle
                end
            end
            local torsoweld = Instance.new("Weld",middle)
            torsoweld.Part0 = hit.Parent.Torso
            torsoweld.Part1 = middle
            torsoweld.C0 = CFrame.new(0,0,0)
        end
    end
end)

Answer this question