Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What's the problem with this bullet creator?

I get bad argument #2 to '?' (Vector3 expected, got nil) as an error for this script.

function CreateBullet(Direction)
	local Origin = GunModel.Barrel.CFrame.p
	local BulletMass = BulletSize.X * BulletSize.Y * BulletSize.Z
	local BulletCF = CF(Origin, Origin + Direction)
	local Bullet = Instance.new("Part")
	Bullet.BrickColor = BulletColor
	Bullet.Name = "Bullet"
	Bullet.CanCollide = false
	Bullet.FormFactor = "Custom"
	Bullet.Size = BulletSize
	Bullet.BottomSurface = "Smooth"
	Bullet.TopSurface = "Smooth"
	local Mesh = Instance.new("BlockMesh")
	Mesh.Scale = BulletMeshSize
	Mesh.Parent = Bullet
	local BF = Instance.new("BodyForce")
	BF.force = Vector3.new(0, BulletMass * (196.2 - BulletDropPerSecond), 0)
	BF.Parent = Bullet
	Bullet.Parent = Gun
	Bullet.CFrame = BulletCF + Direction * 3
	Bullet.Velocity = Direction * BulletVelocity
end
Mouse.Button1Down:connect(CreateBullet)

3 comments

1

what line is the error on??

0

Line 04

0

NinjoOnline ^

1 answer

✓ Accepted answer

You need to fire the function with arguments. You are telling it to shoot it toward nil and it wants a Vector3 so You need to fire it like this:

Mouse.Button1Down:connect(function()
	--Create a formula here to find out what direction to fire it.
	CreateBullet(Direction)
end)

1 comment

0

But I want it to fire where the player's looking and Idk how to do that.

This discussion is preserved as it was. New answers, comments, and votes are closed.