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.
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.
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.
@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)
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.