How to throw tool?

I’m currently trying to create a throw tool script and I can’t achieve it. I have tried using Vector, but that didn’t work at all. Here’s what my code looks like:

local tool = script.Parent
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(key, gp)
	if gp then return end
	if key.KeyCode == Enum.KeyCode.E then
		tool.Parent = workspace
	end
end)

That’s as far as I got before messing up my code with random stuff because I didn’t know what I was doing.

1 Like

Does the tool immediately pick up after you throw it? You might have to move it forward some after you re-parent it.

How would I go about moving it? Also, I’m not looking for a drop I’m looking for a throw. That’s why I tried to use vector.

To throw tool, you need use Player.Character.PrimaryPart.CFrame.LookVector, Tool.Handle.LinearVelocity. Firstly, you need set Power - how far you will throw tool. Then, you need set Tool.Handle.LinearVelocity = Player.Character.PrimaryPart.CFrame.LookVector * Power
This will give Velocity to tool. It will be thrown from player with Power.

Sorry, maybe this wo’t work, bc I don’t tested this in studio. I’ll test it when I return home from college.

3 Likes

I’ve never used linear velocity before, so I’m a bit confused with what you’re saying

Linear velocity will give impulse to object. For example: if you will set LinearVelocity to (0,100,0), object will be thrown upwards.
AngularVelocity is the same, but it ROTATES object, instead of moving it. Set AngularVelocity to (0,100,0), object will spin.

Now, i won’t answer for 5-6 hours

1 Like

Have you found a solution yet?

@GameEditoPro Had given you the solution but to be implemented it looks like this

local tool = script.Parent
local UIS = game:GetService("UserInputService")
local Power = 50 -- Or however far you want it to go
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 = Player.Character.PrimaryPart.Position + Player.Character.PrimaryPart.CFrame.LookVector * 3
        tool.Handle.LinearVelocity = Player.Character.PrimaryPart.CFrame.LookVector * Power
	end
end)
2 Likes

How would I find the player from the script?

Just use Character, the script example has errors referencing Player.Character.PrimaryPart when it really just needs Character.PrimaryPart.

Still doesn’t work… any other errors you see? I don’t see any in the output.

I also have CanBeDropped on if that changes anything.

that probably unequipped the tool before your throw code executes, try turning it off. tool.Handle.LinearVelocity might need to be changed to tool.Handle.AssemblyLinearVelocity but that should show an error in the script if it gets to that point. try using breakpoints to see if the script gets run at all.

1 Like