Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What's the problem with this bullet creator?

Asked by 9 years ago

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)
1
what line is the error on?? NinjoOnline 1146 — 9y
0
Line 04 ScriptingCon 52 — 9y
0
NinjoOnline ^ ScriptingCon 52 — 9y

1 answer

Log in to vote
-1
Answered by 9 years ago

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)
0
But I want it to fire where the player's looking and Idk how to do that. ScriptingCon 52 — 9y
Ad

Answer this question