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)

2 comments
this is a local, or server script?
this is a server script