How do I fix this issue (I believe it's a welding issue)?
I'm trying to make it so when you click on a GUI thing a hat comes on. When I do this the pin badge on the hat goes miles away from the head where the main hat is. I will show you my script and an image to help you picture this.
01 | game.ReplicatedStorage.hat.OnServerEvent:Connect( function (player,name) |
02 | local d = game.Workspace [ player.Name ] :GetChildren() |
04 | if (d [ i ] .className = = "Accessory" ) then |
08 | local g = game.ServerStorage.Hats [ name ] .Face:Clone() |
09 | g.Parent = game.Workspace [ player.Name ] .Head |
10 | local C = g:GetChildren() |
12 | if C [ i ] .className = = "Part" or C [ i ] .className = = "UnionOperation" or C [ i ] .className = = "MeshPart" then |
13 | local W = Instance.new( "Weld" ) |
16 | local CJ = CFrame.new(g.Middle.Position) |
17 | local C 0 = g.Middle.CFrame:inverse()*CJ |
18 | local C 1 = C [ i ] .CFrame:inverse()*CJ |
22 | g.Middle.Transparency = 1 |
25 | local Y = Instance.new( "Weld" ) |
26 | Y.Part 0 = game.Workspace [ player.Name ] .Head |
28 | Y.C 0 = CFrame.new( 0 , 0 , 0 ) |
30 | local h = g:GetChildren() |
33 | h [ i ] .CanCollide = false |
The problem photo