Hey,
I wanted to make a script where the player is able to connect themself with a rope to the terrain where the player clicks.
My problem is that when the player clicks it connects them to the middle of the terrain and not exactly where they click
how can I fix this?
My script:
local mouse = game.Players.LocalPlayer:GetMouse()
local Target = mouse.Target
local Rope = Instance.new("RopeConstraint")
local at1 = Instance.new("Attachment")
at1.Name = "At1"
local at2 = Instance.new("Attachment")
at2.Name = "At2"
local chr = game.Players.LocalPlayer.Character
local hum = chr:FindFirstChild("HumanoidRootPart")
mouse.Button1Down:Connect(function()
if Target.Name == "Terrain" then
at1.Position = Target.Position
at1.Parent = workspace.Terrain
at2.Parent = hum
Rope.Parent = hum
Rope.Attachment0 = at1
Rope.Attachment1 = at2
Rope.Length = ((at1.WorldPosition - at2.WorldPosition).Magnitude)
Rope.Color = BrickColor.Black()
end
end)
I can’t even get it to work.
Neither the rope or the attachment shows up in the character.
I might know a way to fix this though.
local mouse = game.Players.LocalPlayer:GetMouse()
local Rope = Instance.new("RopeConstraint")
local at1 = Instance.new("Attachment")
at1.Name = "At1"
local at2 = Instance.new("Attachment")
at2.Name = "At2"
local chr = game.Players.LocalPlayer.Character
local hum = chr:FindFirstChild("HumanoidRootPart")
mouse.Button1Down:Connect(function()
local Target = mouse.Target --Get the target when they click and not when the script first runs
if Target.Name == "Terrain" then
at1.Position = mouse.hit.p--The position of their click. Terrains position will always be 0,0,0
at1.Parent = workspace.Terrain
at2.Parent = hum
Rope.Parent = hum
Rope.Attachment0 = at1
Rope.Attachment1 = at2
Rope.Length = ((at1.WorldPosition - at2.WorldPosition).Magnitude)
Rope.Color = BrickColor.Black()
end
end)