How To Make A Part Thrown?

Hey, it’s me Army, and today I’m asking another question. :smiley:

So lately, I’ve been trying to make somthing that players can throw, I’ve planned most of the script, but what I cannot find out is how to make the part thrown.

I have, as you should when making a post, have also looked for a solution. One of them was what I was looking for, but it had a target. I looked at BodyVelocity, but the movement is constant force, while I’m only looking for a short pulse, similar to an object in a slingshot.

No target, no constant movement. Just trying to get a part to go in a short throwing motion.

Like last time, any help is appreciated, and I would defenetly look at all of the comments, as a lot more are useful other than the one i put as the solution

And yes, I will try to reply to most comments. :grinning_face_with_smiling_eyes:

5 Likes

You could try using ApplyImpulse and just messing around with the amount of force you want to throw the object with.

https://developer.roblox.com/en-us/api-reference/function/BasePart/ApplyImpulse

1 Like

Do you have any example on how to use it?

1 Like

what you can do is use body velocity, but while it isn’t active set the max force to vector3.new(0,0,0) and while it is have it as something above 0, you can set it to 0 again a little bit after you throw it so that its not constant anymore.

1 Like

this might help you

1 Like

Tried just now, I edited the script a bit to look like this:

local Part = script.Parent

wait(3)

Part:ApplyImpulse(Vector3.new(0,10,0))

Nothing happened after 3 seconds. No error, nothing. Did I do somthing wrong?

1 Like

this should make it do something character.PrimaryPart.CFrame.LookVector * 1000

you can probably do something like

local dir = character.PrimaryPart.CFrame.LookVector * 100 + Vector3.new(0,10,0)
Part:ApplyImpulse(dir)
1 Like

Well, I’m just trying to put force on a part by itself to test it

1 Like

try giving it more force, like Vector3.new(0,100,0) or something

1 Like

Heres an example (just incase you still need it)

This is just done in a local script, you will need to modify it to work in your situation. This will fire a part in the direction of your mouse.

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
	local part = Instance.new("Part")
	part.Size = Vector3.new(1,1,1)
	part.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,3,0)
	part.Parent = workspace
	local direction = mouse.Hit.LookVector -- get the direction we want the part to go in
	local forceMultipliter = 100 * part:GetMass() -- we get the parts mass to make sure that if the part is bigger or smaller it will still go about the same distance
	part:ApplyImpulse(direction * forceMultipliter)
end)
	
9 Likes

Alright, Problem.

So apparently Roblox moved the player to a model in the workspace, is this what I would need to edit?

1 Like

You will need to make changes so that it fits with the rest of your game. If you are storing the players elsewhere (such as a model in workspace) then yes, you will need to change that. Because this is also in a local script, only you will be able to see the part fired. If you want for other players to see the object then you will have to work with remotes.

1 Like

Alright, it moved. Not a lot, but it moved.

1 Like

Thank you, but this raised another question.

I’m not storing any characters into code, I’m trying the code in a blank baseplate template.

Is it only me that it does it to?

1 Like

If you were to upload a game with only a local script with the code I sent before in it and you were to get others to join, only the person “throwing” the parts would be able to see their parts (aka the parts don’t replicate). If you want everyone to be able to see the parts, you will need to work with remotes.

1 Like

(Sorry I’m late) So would you put it in Starter Scripts?

1 Like

You can put it anywhere a local script can run.

1 Like

Had to put it in the player model for it to run.

1 Like