Grappling script not working; Teleporting me to the target instead

Hey! I’m making a Grappling script, but for some reason it’s teleporting me to my target directly, even though it should be lerping (I tried tweening before aswell, acted the same way).

Here is a video about the behaviour:
https://streamable.com/qbpea2

Here is my code:
(Server → This is when it receives the remote event from the client whenever he presses F)

local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local remote = replicatedStorage.R 
local activate = replicatedStorage.A 

activate.OnServerEvent:Connect(function(plr)
	local character = plr.Character or plr.CharacterAdded:Wait()
	local humanoidRootPart = character.HumanoidRootPart
	local hisMousePosition = remote:InvokeClient(plr) --Returns mouse.Hit (CFrame Value) 

	local i = Instance.new("Part")
	i.CFrame = hisMousePosition 
	i.Anchored = true
	i.CanCollide = false 
	i.Transparency = 1
	i.Name = plr.Name .. "'s target"
	i.Parent = workspace
	
	--Creating the Attachments
	local attachment1 = Instance.new("Attachment")
	attachment1.Parent = humanoidRootPart
	--Creating the Attachments
	local attachment2 = Instance.new("Attachment")
	attachment2.Parent = i
	--Creating the rope 
	local ropeConstraint = Instance.new("RopeConstraint")
	ropeConstraint.Attachment0 = attachment1
	ropeConstraint.Attachment1 = attachment2
	ropeConstraint.Visible = true
	ropeConstraint.Thickness = 0.15
	ropeConstraint.Name = "Attachment"
	ropeConstraint.Parent = workspace

	for n = 0, 1, 0.1 do
		wait()
		humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(i.CFrame, n)
	end
	--Destroy the unnecessary parts
	i:Destroy()
	ropeConstraint:Destroy()
	attachment1:Destroy()
	attachment2:Destroy()
end)

This one is probably the most important part

--(Line 34-37)
for n = 0, 1, 0.1 do
		wait()
		humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(i.CFrame, n)
	end

Thank you!

What does this look like when you try to increase the for n loop or increment the wait() to delay 1 second each time? If it’s still teleporting then it’s probably something to do with your lerpings.

1 Like

It looks like this with a wait(1)
https://streamable.com/3s5t6z
and like this with a for n = 0, 1, 0.01 do wait() …
https://streamable.com/lhmd9v

what happens if you first save the current position of the body
and use that

	for n = 0, 1, 0.1 do
		wait()
		humanoidRootPart.CFrame = current_position:Lerp(i.CFrame, n)
	end
1 Like

Same thing as in the video shown above. It teleports.
Script:

local currentCFrame = humanoidRootPart.CFrame

	for n = 0, 1, 0.1 do
		wait()
		humanoidRootPart.CFrame = currentCFrame:Lerp(i.CFrame, n)
	end

Just found out that it works fine when destroying the attachment stuff directly and using tweenService.

humanoidRootPart.Anchored = true
	tweenService:Create(humanoidRootPart, TweenInfo.new(2, Enum.EasingStyle.Linear), {CFrame = i.CFrame}):Play()
	--Destroy the unnecessary parts
	i:Destroy()
	ropeConstraint:Destroy()
	attachment1:Destroy()
	attachment2:Destroy()

That’s weird. But I kinda need them though.
So that means that this part is the problem

	local i = Instance.new("Part")
	i.CFrame = hisMousePosition 
	i.Anchored = true
	i.CanCollide = false 
	i.Transparency = 1
	i.Name = plr.Name .. "'s target"
	i.Parent = workspace
	
	--Creating the Attachments
	local attachment1 = Instance.new("Attachment")
	attachment1.Parent = humanoidRootPart
	--Creating the Attachments
	local attachment2 = Instance.new("Attachment")
	attachment2.Parent = i
	--Creating the rope 
	local ropeConstraint = Instance.new("RopeConstraint")
	ropeConstraint.Attachment0 = attachment1
	ropeConstraint.Attachment1 = attachment2
	ropeConstraint.Visible = true
	ropeConstraint.Thickness = 0.15
	ropeConstraint.Name = "Attachment"
	ropeConstraint.Parent = workspace

Found the solution! It’s that the HumanoidRootPart has to be anchored.

    humanoidRootPart.Anchored = true
	tweenService:Create(humanoidRootPart, TweenInfo.new(2, Enum.EasingStyle.Linear), {CFrame = i.CFrame}):Play()
	--Destroy the unnecessary parts
	wait(2)
	i:Destroy()
	ropeConstraint:Destroy()
	attachment1:Destroy()
	attachment2:Destroy()

Works fine!