I am trying to weld a part to a player when they join the game, but it only happens to one person. Unless starting servers from roblox studio is messed up, because I put 2 players in, and on Player 2's screen, Player 1 has the part welded to him, but Player 2 doesn't. Then if I go onto Player 1's screen, none of them have it. Plus I look at the server window and in the output it says "An error occurred" and both of the players have it on. Here is the script:
01 | local function weldBetween(a, b) |
02 | print (a, b) |
03 | local weld = Instance.new( "ManualWeld" , a) |
04 | weld.Part 0 = a |
05 | weld.Part 1 = b |
06 | weld.C 0 = b.CFrame:inverse() * b.CFrame |
07 | a.LocalTransparencyModifier = 0 |
08 | a.Parent = b |
09 | return weld |
10 | end |
11 |
12 | game.Players.PlayerAdded:connect( function (plr) |
13 | plr.CharacterAdded:connect( function (chr) |
14 | local part = Instance.new( "Part" , game.Workspace) |
15 | part.Name = "Welded Part" |
16 | part.Size = Vector 3. new( 2 , 2 , 2 ) |
17 | local weld = weldBetween(part, chr.Torso) |
18 | end ) |
19 | end ) |
I'm not sure what exactly is wrong, but I spotted few mistakes. It should work fine once fixed.
01 | local function weldBetween(a, b) |
02 | print (a, b) |
03 | -- Why use manualWeld? Just use regular one |
04 | local weld = Instance.new( "Weld" , a) |
05 | weld.Part 0 = a |
06 | weld.Part 1 = b |
07 | -- You inversed b cframe and multiplied with b cframe, which would result into empty CFrame |
08 | -- instead, inverse origin and multiply with other cframe |
09 | weld.C 0 = a.CFrame:inverse() * b.CFrame |
10 |
11 | -- Not sure where you were going with these lines, especially parenting a part to b |
12 | -- a.LocalTransparencyModifier = 0 |
13 | -- a.Parent = b |
14 | return weld |
15 | end |