I have made a basic gun and so far, i can spawn a little bullet of random color, but no matter what i do, I cannot make this bullet have any velocity to it. I have tried looking at many different guides and tutorials to no success, much help is appreciated. Here is the script:
local Tool = script.Parent
local debounce = false
Tool.Equipped:connect(function(Mouse)
01 | Mouse.Button 1 Down:connect( function () |
02 |
03 |
04 | print ( "Firing" ) |
05 |
06 |
07 | local bullet = Instance.new( "Part" ) |
08 |
09 |
10 | bullet.Size = Vector 3. new( 0.10 , 0.2 , 0.2 ) |
11 |
12 |
13 | bullet.BrickColor = BrickColor:random() |
14 |
15 |
end)
01 | Mouse.Button 1 Down:connect( function () |
02 | print ( "Firing!" ) |
03 | local bullet = Instance.new( "Part" , workspace) --Creates the instance in workspace |
04 | bullet.Size = Vector 3. new(. 1 , . 2 , . 2 ) --The same size you wanted just made more simpler |
05 | bullet.BrickColor = BrickColor:random() |
06 | local pos = Tool:WaitForChild( "Barrel" ).Position --Added WaitForChild so it won't run script without loading this! |
07 | local focus = mouse.Hit.p |
08 | bullet.CFrame = CFrame.new(pos, focus) --CFrame is more efficient than Position |
09 | bullet.CFrame = bullet.CFrame + bullet.CFrame.lookVector * 5 -- Get's the way the tool is facing and creates the bullet in front it. you can change number for how far you want the bullet to be when it is created |
10 | local v = Instance.new( "BodyVelocity" ,bullet) |
11 | v.Velocity = bullet.CFrame.lookVector * 500 --Change to whatever number you want(how fast you want it) |
12 | v.MaxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
13 | end ) |
Hope this works out for you. You can change the the numbers around to suit your needs.