i have a script thats supposed to make any player throw an object, but its not working properly, the pick up part works, but the apply impulse part doesn’t, what happens is that it either gets stuck on the air or just falls endlessly
vid:
and it also gets stuck sometimes:
here’s the code:
-- character, player, services...
local heldThrowable = nil
local weldConstraint = nil
local lastTouchTime = 0 -- New variable to track the last touch time
local function setupThrowable(throwable)
throwable.Touched:Connect(function(hit)
if heldThrowable then return end -- don't pick up if already holding something
local currentTime = tick()
if currentTime - lastTouchTime < 5 then return end -- Check if 5 seconds have passed
local touchedCharacter = hit.Parent
local humanoid = touchedCharacter:FindFirstChildOfClass("Humanoid")
if humanoid and touchedCharacter == character then
heldThrowable = throwable
local head = character:FindFirstChild("Head")
weldConstraint = Instance.new("WeldConstraint")
throwable.Anchored = false
weldConstraint.Parent = head
weldConstraint.Part0 = head
weldConstraint.Part1 = throwable
throwable.CFrame = head.CFrame * CFrame.new(0, 1, -2)
lastTouchTime = currentTime -- Update the last touch time
end
end)
end
local function throwObject()
if heldThrowable then
weldConstraint:Destroy()
local throwDirection = humanoidRootPart.CFrame.LookVector * Vector3.new(0,10,0)
local throwForce = throwDirection * heldThrowable:GetMass() * 5000
--heldThrowable:ApplyImpulse(throwForce)
heldThrowable.AssemblyLinearVelocity = throwForce
heldThrowable = nil
end
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.Q and not gameProcessed then
throwObject()
end
end)
for _, throwable in ipairs(CollectionService:GetTagged("Throwable")) do
setupThrowable(throwable)
end
CollectionService:GetInstanceAddedSignal("Throwable"):Connect(setupThrowable)
thanks for the user below for helping
note: i used a remote function to set the network owner ship to the player