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)
Mouse.Button1Down:connect(function() print("Firing") local bullet = Instance.new("Part") bullet.Size = Vector3.new(0.10,0.2,0.2) bullet.BrickColor = BrickColor:random() bullet.Position = Tool.Barrel.Position bullet.Parent = game.Workspace end)
end)
Mouse.Button1Down:connect(function() print("Firing!") local bullet = Instance.new("Part", workspace) --Creates the instance in workspace bullet.Size = Vector3.new(.1, .2, .2) --The same size you wanted just made more simpler bullet.BrickColor = BrickColor:random() local pos = Tool:WaitForChild("Barrel").Position --Added WaitForChild so it won't run script without loading this! local focus = mouse.Hit.p bullet.CFrame = CFrame.new(pos, focus) --CFrame is more efficient than Position 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 local v = Instance.new("BodyVelocity",bullet) v.Velocity = bullet.CFrame.lookVector * 500 --Change to whatever number you want(how fast you want it) v.MaxForce = Vector3.new(math.huge, math.huge, math.huge) end)
Hope this works out for you. You can change the the numbers around to suit your needs.