How to make grappling hook?

So I’ve been trying to make a grappling hook and I don’t know how so far, I’ve made a somewhat working script but its not really good at all

Heres the local script in starter character scripts

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
	if mouse.Target ~= nil then
		script.OdmScript:FireServer(mouse.Target,mouse.Hit)
	end
end)

And heres the server script:

script.Parent.OnServerEvent:Connect(function(plr,target,hit)
	local char = plr.Character
	local root = char.HumanoidRootPart
	local hum = char.Humanoid
	local bv = Instance.new("BodyVelocity")
	bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	bv.Velocity = hit.lookVector *50
	bv.Parent = root
end)

I don’t really care about the hooks I’m just trying to make an efficient system such as making it stop when you reach your position and stuff so any help would be really appreciated and I hope you have a great rest of your day!

2 Likes

Like a tool grappling hook? Take a look at the official grappling hook gear:

1 Like

The thing is that script is too complicated for me so I cant really understand it ;(

Can’t you just destroy the BodyVelocity either after the force is applied or when the player lands?

Example:

hum.StateChanged:Connect(function(old, new)
	if old == Enum.HumanoidStateType.Freefall and new == Enum.HumanoidStateType.Landed then
		bv:Destroy()
	end
end)

If you need more consistency consider trying BodyPosition instead of BodyVelocity.


It’s hard to guess what you mean by just “not really good at all”, could you send some footage or at least elaborate further about what’s wrong with your current grapple hook? Current code looks alright to me.

Regardless, I’ll try to answer based on a grapple hook thing I made recently, everything below is assuming you still use the code you provided.


First, I’d personally make it entirely on the client to avoid unnecessary code and input delays (unless you have any reason to make it server sided such as exploiting, 100% up to you).


Going to assume this means you don’t care about visuals so i’m skipping that. To resume it, you could use attachments on the hands/target and beams, as well as animations for a rope/grapple hook visual effect.


And last, to prevent physics issues (which is what I assume makes your script “not really good at all”?) I personally use the following line to prevent the humanoid from going crazy if they collide with something on the middle of a transition:

hum:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)

As well as:

hum.AutoRotate = false
char:SetPrimaryPartCFrame(CFrame.new(root.Position, target.Position))

To:
.Prevent the player from rotating their character while the grapple hook is currently being used.
.Make them face the correct position.


All of these are obviously set back to their default values once the transition is done, which is something that doesn’t look like you did when it comes to destroying the BodyVelocity.


As an additional note, there is already a pretty good available grapple hook resource:
[open source] sekiro grapple hook

And in case you want to check the code of mine for reference, here’s a file and a preview. You’ll have to make it work with the mouse yourself tho:
Grapple Hook-Movable Boxes System.rbxl