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.
local part = script.Parent local ClickDetector = Instance.new("ClickDetector") local serverStorage = game:GetService("ServerStorage") ClickDetector.Parent = part ClickDetector.MouseClick:Connect(function(player) local tool = player.Backpack.Kosiarka local pos = tool.Socket.Position tool.Socket:Destroy() local newTurret = serverStorage.Turret:Clone() newTurret.Position = pos newTurret.Parent = tool local weld = Instance.new("Weld", newTurret.Part) weld.Part0 = newTurret.Part weld.Part1 = tool.Union1 weld.C0 = newTurret.Part.CFrame:inverse() * tool.Union1.CFrame end)
Hello, if you have something in backpack, it does not have position, it is not placed in workspace!
Instead of setting pos's position as the position variable of the socket (Line 8), try making pos the CFrame of the socket. In other words change:
local pos = tool.Socket.Position (Line 8)
to
local pos = tool.Socket.CFrame