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!!!
