Gun fails to fire, no errors occur

So, I am lurking about to try and improve my understanding of lua a bit more and decided ‘hey, why not make a gun?’ (worst mistake of my life).

So far, what is working is:

  • When the tool is activated, it is able to make a noise

What isn’t working:

  • No bullet is cloned (apparently)
  • No errors occur

Sorry if the script is a bit messy, I’ve been on a big hiatus while I focused on exams and have only recently moved back into developing on Roblox.

local gun = script.Parent
local ServerStorage = game:GetService("ServerStorage")
local tool = script.Parent.Parent
local shot = gun.GunShot

local dist = 200
local count = 0

local function onClick()

	local bullet = ServerStorage.Bullet:Clone()
	local bulletpos = bullet.Position
	bulletpos = Vector3.new(gun.Position)
	
	shot.TimePosition = 0
	shot.Playing = true
	wait(shot.TimeLength)
	
	while dist > count do
		bulletpos = Vector3.new(bulletpos.X+1,bulletpos.Y,bulletpos.Z)
		count = count + 1
	end
	bullet:Destroy()
	
end

tool.Activated:Connect(onClick)

Note: I haven’t followed any one tutorial, and have mostly went off browsing the dev forum and reading documentation.

(If you’re wondering why it only goes in the X axis, I’m trying to get it to fire a projectile, not fire at the mouse direction, for now)

You never set the bullets parent to workspace

but theres also couple of errors i notice:

  • you can just use shot:Play() instead of all that stuff
  • you can just replace line 12 and 13 with bulletpos = gun.Position
  • and the way you move the bullet isnt that nice I reccomend puting a body velocity in it with the velocity being the bullet’s cframe’s lookvector times the bullet speed
    (and using .touched on the bullet instead of while true do)
1 Like