I’ve just followed Cookie Tech’s tutorial on YouTube on the Grapple Hook System.
A RopeConstraint didn’t work for me (It worked fine, it’s just not what I was looking for), So I modified it to work with a RodConstraint.
When you let go of your mouseclick, it will stop the grapple, but the player loses all of their speed. I’d like the player to retain velocity after letting go of the grapple. How can I do this?
Script Dropdown
local uis = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local humanoid = player.Character:WaitForChild("Humanoid")
local root = player.Character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local keybind = Enum.KeyCode.E
local keydown = false
local debounce = false
local range = 300
local speed = 500
local ropeVisible = true
local ropeThickness = 0.2
local ropeColor = BrickColor.DarkGray()
local targetTransparency = 0.5
function vector_dist(a, b)
local diff = a - b
local dist = diff.Magnitude
dist = math.floor(dist/1+0.5) * 1
return dist
end
function attach(method, parent)
if method == "Create" then
local attachment = Instance.new("Attachment")
attachment.Parent = parent
elseif method == "Destroy" then
parent.Attachment:Destroy()
end
end
uis.InputEnded:Connect(function(key)
if key.KeyCode == keybind then
keydown = false
end
end)
uis.InputBegan:Connect(function(key)
if key.KeyCode ~= keybind then return end
keydown = true
if not debounce then
debounce = true
local hitpos = mouse.Hit.Position
local dist = vector_dist(hitpos, root.Position)
if dist <= range then
local grappletarget = Instance.new("Part")
grappletarget.Anchored = true
grappletarget.Parent = game:GetService("Workspace")
grappletarget.Position = hitpos
grappletarget.Transparency = targetTransparency
grappletarget.Size = Vector3.new(1, 1, 1)
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
attach("Create", grappletarget)
attach("Create", root)
local ropeConstraint = Instance.new("RodConstraint")
ropeConstraint.Parent = grappletarget
ropeConstraint.Attachment0 = grappletarget.Attachment
ropeConstraint.Attachment1 = root.Attachment
ropeConstraint.Color = ropeColor
ropeConstraint.Visible = ropeVisible
ropeConstraint.Thickness = ropeThickness
ropeConstraint.Length = 2
repeat wait() until not keydown
attach("Destroy", grappletarget)
attach("Destroy", root)
grappletarget.RodConstraint:Destroy()
grappletarget:Destroy()
humanoid:ChangeState(Enum.HumanoidStateType.Running)
end
debounce = false
end
end)