Code creates attachment to wrong possition. And when the player clicks to an anchored part, Rope.WinchSpeed is not working
local Players = game:GetService("Players")
local Mouse = Players.LocalPlayer:GetMouse()
local function onButton1Down()
local character = Players.LocalPlayer.Character
if not character then
return
end
local leftHand = character:FindFirstChild("LeftHand")
if not leftHand then
return
end
local target = Mouse.Target
if not target then
return
end
local ip = leftHand:FindFirstChild("RopeConstraint")
if not ip then
local Rope = Instance.new("RopeConstraint")
Rope.Parent = leftHand
Rope.Length = (leftHand.Position - target.Position).Magnitude
Rope.WinchEnabled = true
Rope.WinchSpeed = 100
Rope.Visible = true
local At1 = Instance.new("Attachment")
At1.Position = Mouse.Target.Position
At1.Parent = target
At1.Name = "Attachment0"
Rope.Attachment0 = At1
local At2 = Instance.new("Attachment")
At2.Parent = leftHand
At2.Name = "Attachment1"
Rope.Attachment1 = At2
else
ip:Destroy()
end
end
Mouse.Button1Down:Connect(onButton1Down)
Set The WorldPosition of the Attachment to the Position. Position on the Attachment is based on off the Object space of its parent, or simply its Local Axis
Don’t set the position of At1. The attachment’s WorldPosition is already set to the same position as the part you parent it to. By setting Position, you’re offsetting it. Remove this line:
local Players = game:GetService("Players")
local Mouse = Players.LocalPlayer:GetMouse()
local function onButton1Down()
local character = Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
if not character then
return
end
local leftHand = character:FindFirstChild("LeftHand")
if not leftHand then
return
end
local target = Mouse.Target
if not target then
return
end
local ip = leftHand:FindFirstChild("RopeConstraint")
if not ip then
local Rope = Instance.new("RopeConstraint")
Rope.Parent = leftHand
Rope.Length = (leftHand.Position - target.Position).Magnitude
Rope.WinchEnabled = true
Rope.WinchSpeed = 100
Rope.Visible = true
local At1 = Instance.new("Attachment")
At1.Parent = target
At1.Name = "Attachment0"
Rope.Attachment0 = At1
local At2 = Instance.new("Attachment")
At2.Parent = leftHand
At2.Name = "Attachment1"
Rope.Attachment1 = At2
else
ip:Destroy()
end
end
Mouse.Button1Down:Connect(onButton1Down)