Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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.

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

0

this is a local, or server script?

0

this is a server script

2 answers

✓ Accepted answer

Hello, if you have something in backpack, it does not have position, it is not placed in workspace!

1 comment

0

Ohh, that makes sense. How can I weld it correctly then?

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

1 comment

0

The part is still not on the socket's position, I get no errors

This discussion is preserved as it was. New answers, comments, and votes are closed.