Help with making a throwable object

Hello, I’m trying to script a throwable object, but I’m unclear of how to do it. Here’s what I want to add.

  1. I want to add a working damage system
  2. A physics system for it so it can act like a real object
  3. And a cooldown so it doesn’t get spammed for lots of damage instantly.

I have looked for some solutions, but I haven’t found a good system that can help me with this.
Here’s what I have so far.

local EggObject = script.Parent
local Remote = EggObject:WaitForChild("Remote")
local Handle = EggObject:WaitForChild("Handle")

local FriendlyFire = true


function getEgg()
	local Egg = Handle:clone()
	Egg.Transparency = 0

	local lift = Instance.new("BodyForce")
	lift.force = Vector3.new(0, 196.2, 0) * Egg:GetMass() * 0.8
	lift.Parent = Egg

	local proj = EggObject.Projectile:Clone()
	proj.Disabled = false
	proj.Parent = Egg

	return Egg
end

2 Likes

You may be interesting in Basepart:ApplyImpulse() and similar functions:

1 Like

What would are other similar functions if you dont mind me asking?

Hopefully this forums post will solve your issue.
How do you make bullets shoot where your mouse is? - Help and Feedback / Scripting Support - Developer Forum | Roblox

The script in the third post of the forum post above this text is slightly outdated since it uses BodyForce which doesn’t work in new work, although it can be replaced with VectorForce instead.

And since you want to make a throwing object, I’d recommend cloning the part that you want to be thrown and making the original part invisible.

2 Likes

And since you want to make a throwing object, I’d recommend cloning the part that you want to be thrown and making the original part invisible.

Would the script below,

local bullet = Instance.new("Part")

In my case, be this instead?

local Egg = Handle:Clone()

Yeah totally! Just if you want to make the illusion that it’s actually thrown, make the original part (not the clone part used for throwing) invisible for a few seconds before becoming visible again.

Ok, I’ll try this out later, thank you.

Basepart:ApplyAngularImpulse() and BasePart:ApplyImpulseAtPosition() have their own use cases you could want to achieve, but most of the time, you’d want to use Basepart:ApplyImpulse()
It’s simple to use. For example, this code block right here would create a part, then launch it.

local Part = Instance.new("Part")
Part.Parent = workspace
Part.Position = Vector3.new(0,10,0)
task.wait(1)

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

You may need something slightly different depending on what you want.

I added these 3 lines,

wait(0.35) do
		Egg.Transparency = 0
	end

In between these two pieces of code,

local lift = Instance.new("BodyForce")
	lift.force = Vector3.new(0, 196.2, 0) * Egg:GetMass() * 0.8
	lift.Parent = Egg

and

local proj = EggObject.Projectile:Clone()
	proj.Disabled = false
	proj.Parent = Egg

Is this correct placement? It didn’t work for me when I did it.

Nevermind, I fixed the script, thank you though!

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