Currently working on a trolley. For the first time when equipping it, it works perfectly fine but the second time when unequipping and equipping again, the trolley is positioned very randomly.
ServerScript:
local mainPart = script.Parent.Prompt
local prompt = mainPart.ProximityPrompt
local model = script.Parent
local H1 = model.H1
for i, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("Part") or v:IsA("BasePart") then
local constraint = Instance.new("WeldConstraint")
constraint.Part0 = v
constraint.Part1 = mainPart
constraint.Parent = v
end
end
equipped = false
prompt.Triggered:Connect(function(plr)
local char = plr.Character
local lArm = char:FindFirstChild("Left Arm")
local rArm = char:FindFirstChild("Right Arm")
local torso = char.Torso
local connection1 = torso["Right Shoulder"]
local connection2 = torso["Left Shoulder"]
if equipped == false then
equipped = true
connection1.Part1 = nil
connection2.Part1 = nil
model:PivotTo(torso.CFrame * CFrame.new(0, -1.25, -4) * CFrame.Angles(math.rad(90), math.rad(0), math.rad(180)))
local weld1 = Instance.new("Weld")
weld1.Part0 = torso
weld1.Parent = torso
weld1.Part1 = lArm
weld1.C1 = CFrame.new(1.5, 0.5, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(-70), 0, math.rad(0))
weld1.Name = "weld1"
local weld2 = Instance.new("Weld")
weld2.Part0 = torso
weld2.Parent = torso
weld2.Part1 = rArm
weld2.C1 = CFrame.new(-1.5, 0.5, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(-70), 0, math.rad(0))
weld2.Name = "weld2"
local weld3 = Instance.new("WeldConstraint")
weld3.Part0 = H1
weld3.Part1 = rArm
weld3.Parent = H1
weld3.Name = "weld3"
elseif equipped == true and torso:FindFirstChild("weld1") then
equipped = false
connection1.Part1 = lArm
connection2.Part1 = rArm
torso.weld1:Destroy()
torso.weld2:Destroy()
H1.weld3:Destroy()
else
equipped = false
end
end)
Pics: