I want to make a bullet script that aims at where the mouse is at. I intend the game to be first person.

-- "plr" is already defined previously as "Tool.Parent" would this still work?
-- "integer" is defined as the value of an ammo IntValue object.
--"scriptfinished" is already defined as a debounce boolean.

function kiddo()
   if not scriptfinished then --debounce
	if integer.Value >= 0 then -- ammo checker
		scriptfinished = true --debounce
		script.d:Play()	
		local bullet = Instance.new("Part")
		bullet.CanCollide = false
		bullet.Parent = game.Workspace
		local mouse = plr:GetMouse() -- 
		bullet.Name = "bullet"
		bullet.CFrame = CFrame.new(Vector3.new(tool.Handle.Position.X,tool.Handle.Position.Y,tool.Handle.Position.Z))
		bullet.Size = Vector3.new(0.01,0.01,0.01)
		local vel = Instance.new("BodyVelocity")
		vel.Parent = bullet
		vel.velocity = Vector3.new() -- What should I put in the brackets?
		bell()
		scriptfinished = false
		integer.Value = (integer.Value - 1)
	else -- second section fires if ammo == 0
		scriptfinished = true --debounce
		script.Empty:Play()
		wait(.3)
		scriptfinished = false - debounce
	end
	
	end
end

Please suggest anything to put in the Vector3 and also suss out potential errors. Please mind that this is in a normal script and not a localscript. The reason why I did the parenting of vel and bullet outside of Instance.new() was because of a desperate attempt to debug.

-ZetaReticuli

2 comments

0

You would want a raycast from the gun's barrel to the mouse point.

0

Please elaborate.