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

Welds fine in StarterPack, but won't weld when taken from ReplicatedStorage?

Asked by 8 years ago

I made a gun system for a FilteringEnabled game I'm making. Something's not right, however. The gun is welded perfectly fine in StarterPack. However, when you get a gun from the shop (The Shop uses ReplicatedStorage) The only part that's in the right position is the handle, everything else is a mess. Here's my weld script:

local PartsThatMove = {}
local StopWeld = false

function Weld(x, y)
    for i,v in pairs(PartsThatMove) do
        if y.Name == v then
            local oldweld = script.Parent.Handle:FindFirstChild(y.Name.."Weld")
            if oldweld then
                StopWeld = true
            end
            break
        end
    end
    if StopWeld then return end
    local W = Instance.new("Weld")
    W.Name = y.Name.."Weld"
    W.Part0 = x
    W.Part1 = y
    local CJ = CFrame.new(x.Position)
    local C0 = x.CFrame:inverse()*CJ
    local C1 = y.CFrame:inverse()*CJ
    W.C0 = C0
    W.C1 = C1
    W.Parent = x
    local CFValue = Instance.new("CFrameValue", script.Parent.Bin.MPW)
    CFValue.Value = W.C1
    CFValue.Name = y.Name.."C1"
end

function Get(A)
    if A:IsA("BasePart") and A.Name ~= "Handle" then
        Weld(script.Parent:WaitForChild("Handle"), A)
        print("Welded")
        StopWeld = false
        A.Anchored = false
        A.CanCollide = false
    elseif not A:IsA("BasePart") then
        local C = A:GetChildren()
        for i=1, #C do
        Get(C[i])
        end
    elseif A.Name == "Handle" then
        A.Anchored = false
        A.CanCollide = false
    end
end

function Finale()
    Get(script.Parent)
end

script.Parent.Equipped:connect(Finale)
script.Parent.Unequipped:connect(Finale)
Finale()

I just added in the print("Welded") part. I'm about to test it

Answer this question