Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is the position not changing?

Asked by 3 years ago

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.

01local part = script.Parent
02local ClickDetector = Instance.new("ClickDetector")
03local serverStorage = game:GetService("ServerStorage")
04 
05ClickDetector.Parent = part
06ClickDetector.MouseClick:Connect(function(player)
07    local tool = player.Backpack.Kosiarka
08    local pos = tool.Socket.Position
09    tool.Socket:Destroy()
10    local newTurret = serverStorage.Turret:Clone()
11    newTurret.Position = pos
12    newTurret.Parent = tool
13 
14    local weld = Instance.new("Weld", newTurret.Part)
15    weld.Part0 = newTurret.Part
16    weld.Part1 = tool.Union1
17    weld.C0 = newTurret.Part.CFrame:inverse() * tool.Union1.CFrame
18 
19end)
0
this is a local, or server script? Xyternal 247 — 3y
0
this is a server script Cymusichan 7 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

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

0
Ohh, that makes sense. How can I weld it correctly then? Cymusichan 7 — 3y
Ad
Log in to vote
0
Answered by
epoke466 100
3 years ago
Edited 3 years ago

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:

1local pos = tool.Socket.Position (Line 8)

to

1local pos = tool.Socket.CFrame
0
The part is still not on the socket's position, I get no errors Cymusichan 7 — 3y

Answer this question