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 2 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.

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)
0
this is a local, or server script? Xyternal 247 — 2y
0
this is a server script Cymusichan 7 — 2y

2 answers

Log in to vote
0
Answered by 2 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 — 2y
Ad
Log in to vote
0
Answered by
epoke466 100
2 years ago
Edited 2 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:

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

to

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

Answer this question