i am trying to make a gun for my game. i have the gun and models i made the first person aspect from the article on this site, but i cant make it shoot bullets.

My code is here: (also i took it from a handgun script and remade it)

	local DebrisService = game:GetService("Debris")
	local Humanoid = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Humanoid")
	
function CreateBullet(bulletPos)
	local bullet = Instance.new('Part', workspace)
	bullet.Size = Vector3.new(0.1, 0.1, 0.1)
	bullet.Shape = Enum.PartType.Block
	bullet.CanCollide = false
	bullet.CFrame = CFrame.new(bulletPos)
	bullet.Anchored = true
	bullet.TopSurface = Enum.SurfaceType.Smooth
	bullet.BottomSurface = Enum.SurfaceType.Smooth
	bullet.Name = 'Bullet'
	DebrisService:AddItem(bullet, 2.5)
	
	local shell = Instance.new("Part")
	shell.CFrame = game.Players.LocalPlayer.Character.M249.Spawner.CFrame * CFrame.fromEulerAnglesXYZ(1.5,0,0)
	shell.Size = Vector3.new(1,1,1)
	shell.Parent = game.Workspace
	shell.CFrame = script.Parent.Handle.CFrame
	shell.CanCollide = false
	shell.Transparency = 0
	shell.BottomSurface = 0
	shell.TopSurface = 0
	shell.Name = "Shell"
	shell.Velocity = game.Players.LocalPlayer.Character.M249.Spawner.CFrame.LookVector * 35 + Vector3.new(math.random(-10,10),20,math.random(-10,20))
	shell.RotVelocity = Vector3.new(0,200,0)
	DebrisService:AddItem(shell, 1)

	local shellmesh = Instance.new("SpecialMesh")
	shellmesh.Scale = Vector3.new(.15,.4,.15)
	shellmesh.Parent = shell
	
	return bullet
end


function OnFire(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
	local Char = game.Players.LocalPlayer.CharacterAdded:Wait().Character
	local Humanoid = Char:WaitForChild("Humanoid")
	local M249 = Char:WaitForChild("M249")
	
	CreateBullet(M249.Spawner.Position)
	end
end

game:GetService("UserInputService").InputBegan:Connect(OnFire)

2 comments

0

Is there anything in the output?

0

no. nothing in the output