This code is supposed to fire a BasePart inside a model using ApplyImpulse after unwelding it from the Base of the Grappel which is in the players arm. The problem is that when the weld is disabled it falls to the floor then applies the impulse which makes the part anchor to the floor instead of anchoring to the desired target. Thanks for any help.
local cooldown = false
local force = 20
function playerProfile:Grapple(mousePosition)
if not self["Active"] and not cooldown then
print("do something")
task.spawn(function()
cooldown = true
task.wait(7)
cooldown = false
end)
local grappelPart = self["Character"].GrappelPart
local grappelWeld = self["Character"].GrappelBase.GrappelWeld
-- Calculate launch direction towards the mouse
local startPosition = grappelPart.Base.Position
local launchDirection = (mousePosition - startPosition).Unit
-- Apply velocity to launch the part
grappelWeld.Enabled = false
task.wait()
grappelPart.Base:ApplyImpulse(launchDirection * force)
for i, v in grappelPart:GetChildren() do
v.Touched:Connect(function(hit)
if hit.Parent.Name ~= self["Name"] then
print(hit)
print(hit.Parent.Name)
grappelPart.Base.Anchored = true
end
end)
end
end
end