#Client sided tool attachment

1 messages · Page 1 of 1 (latest)

grave trench
#

I want the sword to attach to the model however it doesn't work and im unsure why? Any suggestions with what to do?

#

local function attemptOne(viewport, dictonaryOfEquipmentOnUnit)

local model
if dictonaryOfEquipmentOnUnit["Creature"] ~= "" then
    if debugMode then print("Creature exists") end
else
    if debugMode then print("Creature doesnt exist or there was some sort of bug") end
    model = game.ReplicatedStorage:FindFirstChild("Items"):FindFirstChild("Creatures"):FindFirstChild("HiddenModel"):FindFirstChild("Model"):Clone()
end

model.Parent = game.Workspace
model.Name = "attemptOne"

for itemType, value in pairs(dictonaryOfEquipmentOnUnit) do
    if value ~= "" and itemType ~= "Creature" then
        local toolClone = game.ReplicatedStorage.Items[itemType .. "s"][value].Tool:Clone()        --    Use tool because it works with putting equipment on the models 
        toolClone.Parent = model
        if debugMode then print(toolClone) end


        local toolAttachment = toolClone:FindFirstChild("Handle"):FindFirstChildWhichIsA("Attachment")
        local modelAttachment = model:FindFirstChild(toolAttachment.Name, true) -- find matching attachment by name anywhere in model

        print(toolAttachment, modelAttachment)
        -- Create a WeldConstraint between matching attachments
        if toolAttachment and modelAttachment then
            local weld = Instance.new("WeldConstraint")
            weld.Part0 = toolAttachment.Parent
            weld.Part1 = modelAttachment.Parent
            weld.Parent = toolAttachment.Parent

            -- Align the attachments
            toolAttachment.CFrame = modelAttachment.CFrame
        end


    end
end

model.Parent = viewport
model.Parent = game.Workspace


local unitsStats = module.getStatsFromItems(dictonaryOfEquipmentOnUnit)
if debugMode then print("Stats from items:", unitsStats) end

end