Harpoon tool teleporting targets

im trying to make a harpoon tool that can pull in targets and act like a grappling hook, but the harpoon teleports any unanchored targets directly to you instead of pulling you in
my code:

local active = false
local harpoonDeployed = false

local tool = script.Parent.Parent
local handle = script.Parent
local harpoon = tool:WaitForChild("harpoon")
local originalWeld = handle:FindFirstChild("harpoonWeld")
local deployedWeld = nil
local targetPart = nil


local ParasiteMain = require(game.ServerScriptService.ParasiteMain)

local originalCFrame = harpoon.CFrame

handle.Damage.OnServerEvent:Connect(function(player, target, hit)
	if player ~= game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent) then return end
	if target and hit then

		if not harpoonDeployed and not active --[[and target.Anchored == true]] then
			active = true
			harpoonDeployed = true

			if originalWeld then
				originalWeld.Enabled = false
			end
			handle.RopeConstraint.Length = (hit.Position - tool.Handle.Attachment.WorldPosition).Magnitude
			harpoon.CFrame = CFrame.new(hit.Position, tool.Handle.Attachment.WorldPosition)
			deployedWeld = Instance.new("WeldConstraint")
			deployedWeld.Part0 = target
			deployedWeld.Part1 = harpoon
			deployedWeld.Parent = harpoon
			targetPart = target

			if target.Parent:FindFirstChild("Humanoid") then
				ParasiteMain.DamageCharacter(target.Parent, 25, tool.Parent.Name)
			end

			handle.Sound.PlaybackSpeed = math.random(80, 120)/100
			handle.Sound:Play()

			active = false

		elseif harpoonDeployed and not active then
			active = true
			harpoonDeployed = false

			if deployedWeld then
				deployedWeld:Destroy()
				deployedWeld = nil
			end

			if originalWeld then
				originalWeld.Enabled = true
			end
			handle.RopeConstraint.Length = 2.15
			handle.Sound.PlaybackSpeed = math.random(80, 120)/100
			handle.Sound:Play()

			targetPart = nil
			active = false
		end
	end
end)

tool.Equipped:Connect(function()
	harpoonDeployed = false
	active = false
end)

tool.Unequipped:Connect(function()
	if harpoonDeployed then
		if deployedWeld then
			deployedWeld:Destroy()
			deployedWeld = nil
		end

		if originalWeld then
			originalWeld.Enabled = true
		end

		harpoonDeployed = false
	end

	targetPart = nil
	active = false
end)

tool.AncestryChanged:Connect(function()
	if not tool.Parent then
		if deployedWeld then
			deployedWeld:Destroy()
			deployedWeld = nil
		end

		if originalWeld then
			originalWeld.Enabled = true
		end

		harpoonDeployed = false
		targetPart = nil
		active = false
	end
end)

ive tried welding first, using regular welds and not weldconstraints, and a zillion other things but they never worked!!! help!!!

3 Likes

Sorta skimmed through your code and namely watched the video, but its pretty simple (im hoping)

the rope doesnt consider the distance between you and the target (of a humanoid), so it will teleport anything unanchored about 2.5 studs away, which is why it seems to latch onto your harpoon.

1 Like

wdym

	handle.RopeConstraint.Length = (hit.Position - tool.Handle.Attachment.WorldPosition).Magnitude

this makes the rope long enough just to the distance of the 2 points


read bro read :sob:

theres an entirely different if statement that would make the rope 2.15 studs long exclusively and I imagine thats one of the root causes, to clarify.

I believe that in the client script when it calls the script again after it was deployed and not active it sets the distance to 2.15 so it has something to do with that.

handle.RopeConstraint.Length = 2.15

1 Like

mb lol i didn’t finish reading it :joy:

all good :sob:, but yea i imagine it has to be something with the,

rope constraint
and
actual hit logic

1 Like

this is actually the retraction, it disconnects properly and all that, my problem is that when it initially connects it gets teleported

I imagine its instantly performing the retraction considering it might be hitting the rig instantly? rather than letting the projectile travel, and hit the dummy and then retracting.

fixed it with some help on another platform, i had to change the network ownership and add a small wait..

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.