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.
01 | local Gun = script.Parent |
02 | local Handle = Gun.Handle |
03 | local Body = Gun.Body |
04 | local Barrel = Gun.Barrel |
05 |
06 | function Weld() |
07 | local W 1 = Instance.new( "Weld" , Handle) |
08 | W 1. Part 0 = Handle |
09 | W 1. Part 1 = Body |
10 | W 1. C 1 = CFrame.Angles(ANGLE IN RADIANS) * CFrame.new(POSITION IN STUDS) |
11 |
12 | local W 2 = Instance.new( "Weld" , Handle) |
13 | W 2. Part 0 = Handle |
14 | W 2. Part 1 = Body |
15 | W 2. C 1 = CFrame.Angles(ANGLE IN RADIANS) * CFrame.new(POSITION IN STUDS) |
Use this code:
01 | local Gun = script.Parent |
02 | local Handle = Gun.Handle |
03 | local Body = Gun.Body |
04 | local Barrel = Gun.Barrel |
05 | local function createWeld(a, b) |
06 | local weld = Instance.new( "Weld" , Handle) |
07 | weld.Part 0 = a |
08 | weld.Part 1 = b |
09 | weld.C 0 = a.CFrame:inverse() |
10 | weld.C 1 = b.CFrame:inverse() |
11 | end |
12 |
13 | function Weld() |
14 | createWeld(Handle, Body) |
15 |
16 | createWeld(Handle, Barrel) -- Theres only two because you had two welds welding the same thing. |
17 | end |
18 |
19 | Gun.Equipped:connect(Weld) |
20 | Gun.Unequipped:connect(Weld) |
It just welds those parts together like your old code is trying to do.
Use this function instead to create your welds
1 | local function weldBetween(a, b) |
2 | local weld = Instance.new( "ManualWeld" ) |
3 | weld.Part 0 = a |
4 | weld.Part 1 = b |
5 | weld.C 0 = CFrame.new() |
6 | weld.C 1 = b.CFrame:inverse() * a.CFrame |
7 | weld.Parent = a |
8 | return weld; |
9 | end |