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 10 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.

01local Gun = script.Parent
02local Handle = Gun.Handle
03local Body = Gun.Body
04local Barrel = Gun.Barrel
05 
06function Weld()
07    local W1 = Instance.new("Weld", Handle)
08    W1.Part0 = Handle
09    W1.Part1 = Body
10    W1.C1 = CFrame.Angles(ANGLE IN RADIANS) * CFrame.new(POSITION IN STUDS)
11 
12    local W2 = Instance.new("Weld", Handle)
13    W2.Part0 = Handle
14    W2.Part1 = Body
15    W2.C1 = CFrame.Angles(ANGLE IN RADIANS) * CFrame.new(POSITION IN STUDS)
View all 24 lines...

2 answers

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

Use this code:

01local Gun = script.Parent
02local Handle = Gun.Handle
03local Body = Gun.Body
04local Barrel = Gun.Barrel
05local function createWeld(a, b)
06    local weld = Instance.new("Weld", Handle)
07    weld.Part0 = a
08    weld.Part1 = b
09    weld.C0 = a.CFrame:inverse()
10    weld.C1 = b.CFrame:inverse()
11end
12 
13function Weld()
14    createWeld(Handle, Body)
15 
16    createWeld(Handle, Barrel) -- Theres only two because you had two welds welding the same thing.
17end
18 
19Gun.Equipped:connect(Weld)
20Gun.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 10 years ago

Use this function instead to create your welds

1local function weldBetween(a, b)
2        local weld = Instance.new("ManualWeld")
3        weld.Part0 = a
4        weld.Part1 = b
5        weld.C0 = CFrame.new()
6        weld.C1 = b.CFrame:inverse() * a.CFrame
7    weld.Parent = a
8        return weld;
9end
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 — 10y

Answer this question