Why is the position not changing?
I want to make custom attachments for my weapon, in this case I wanted to attach a small turret. The tool has an empty semi-transparent socket which should get replaced by the turret, but the cloned turret doesn't change its position and gets welded somewhere next to the tool. I made a button that replaces socket with a turret when I click it.
01 | local part = script.Parent |
02 | local ClickDetector = Instance.new( "ClickDetector" ) |
03 | local serverStorage = game:GetService( "ServerStorage" ) |
05 | ClickDetector.Parent = part |
06 | ClickDetector.MouseClick:Connect( function (player) |
07 | local tool = player.Backpack.Kosiarka |
08 | local pos = tool.Socket.Position |
10 | local newTurret = serverStorage.Turret:Clone() |
11 | newTurret.Position = pos |
12 | newTurret.Parent = tool |
14 | local weld = Instance.new( "Weld" , newTurret.Part) |
15 | weld.Part 0 = newTurret.Part |
16 | weld.Part 1 = tool.Union 1 |
17 | weld.C 0 = newTurret.Part.CFrame:inverse() * tool.Union 1. CFrame |