How to throw a tool

Hello, I want to make a tool that I can throw. I copied this code from another question, but it doesn’t really work. Once the tool’s parent is workspace, it just teleports a couple of studs in front of me and falls. I want that to happen, but instead of teleporting, it realistically moves to the point.

LinearVelocity properties
image

Attachment properties
image

local tool = script.Parent
local UIS = game:GetService("UserInputService")
local Power = 100
local Character 
local Equipped = false
tool.Equipped:Connect(function()
	Character = tool.Parent
	Equipped = true 
end)
tool.Unequipped:Connect(function()

	Equipped = false 
end)
UIS.InputBegan:Connect(function(key, gp)
	if gp then return end
	if key.KeyCode == Enum.KeyCode.E and Equipped == true then
		
		tool.Parent = workspace
		tool.Handle.Position = Character.PrimaryPart.Position + Character.PrimaryPart.CFrame.LookVector * 3
		tool.Handle.LinearVelocity.VectorVelocity = Character.PrimaryPart.CFrame.LookVector * Power
	end
end)
2 Likes

Look at :ApplyImpulse

Here is a similar post to your question:

1 Like

How did they get this on server?

local tool = script.Parent
local handle = tool.Handle
1 Like

Looks like the Server script would also be inside the Tool.

1 Like

I was hoping for something more realistic, but this works I guess. The only problem is that it goes through the ground, how can I fix that?

1 Like

Some part of your tool will need to be set to CanCollide = true.

You can change that value after the tool is thrown if you want.

1 Like

Thanks, dude! One last question. How can I make it disappear after 1 second on the ground?

1 Like

Create a function with a task.wait() then call it after the tool is thrown.

local function destroyTool()
task.wait(1)
tool:Destroy()
end
1 Like

Didn’t work, so I changed it a little.

destroyTool(projectile)

local function destroyTool(part)
	task.wait(1)
	part:Destroy()
end
1 Like

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