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

Help with Weld script?

Asked by 9 years ago

Hello, I have a Weld script, but I can't get it to work even when a player hasn't taken it. Is there a way to solve it, allowing the tool to be welded from the start? Also, is it possible to make this script smaller?

I will use this to make guns that can be seen when dropped.

Here's the entire script.

local Gun = script.Parent
local Handle = Gun.Handle
local Body = Gun.Body
local Barrel = Gun.Barrel

function Weld()
    local W1 = Instance.new("Weld", Handle)
    W1.Part0 = Handle
    W1.Part1 = Body
    W1.C1 = CFrame.Angles(ANGLE IN RADIANS) * CFrame.new(POSITION IN STUDS)

    local W2 = Instance.new("Weld", Handle)
    W2.Part0 = Handle
    W2.Part1 = Body
    W2.C1 = CFrame.Angles(ANGLE IN RADIANS) * CFrame.new(POSITION IN STUDS)

    local W3 = Instance.new("Weld", Handle)
    W3.Part0 = Handle
    W3.Part1 = Barrel
    W3.C1 = CFrame.Angles(ANGLE IN RADIANS) * CFrame.new(POSITION IN STUDS)
end

Gun.Equipped:connect(Weld)
Gun.Unequipped:connect(Weld)

2 answers

Log in to vote
1
Answered by
Hexcede 52
9 years ago

Use this code:

local Gun = script.Parent
local Handle = Gun.Handle
local Body = Gun.Body
local Barrel = Gun.Barrel
local function createWeld(a, b)
    local weld = Instance.new("Weld", Handle)
    weld.Part0 = a
    weld.Part1 = b
    weld.C0 = a.CFrame:inverse() 
    weld.C1 = b.CFrame:inverse() 
end

function Weld()
    createWeld(Handle, Body)

    createWeld(Handle, Barrel) -- Theres only two because you had two welds welding the same thing.
end

Gun.Equipped:connect(Weld)
Gun.Unequipped:connect(Weld)

It just welds those parts together like your old code is trying to do.

Ad
Log in to vote
0
Answered by 9 years ago

Use this function instead to create your welds

local function weldBetween(a, b)
        local weld = Instance.new("ManualWeld")
        weld.Part0 = a
        weld.Part1 = b
        weld.C0 = CFrame.new()
        weld.C1 = b.CFrame:inverse() * a.CFrame
    weld.Parent = a
        return weld;
end
0
I'm sorry but I can't get it to work. Does it only work to make 1 weld? Because I need to make 3 welds actually :P TheArmoredReaper 173 — 9y

Answer this question