Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My Firing Projectile Isn't Working?

Here's the local script, and thank you for looking at my question.

Player = game.Players.LocalPlayer

Gun = script.Parent

Ammo = 5

mouse = Player:GetMouse()

function Shoot()
	
	if Ammo > 0 then
		local Bullet = Instance.new("Part", workspace)
		game.Debris:addItem(Bullet, 2)
		Bullet.Shape = "Ball"
		Bullet.Size = Vector3.new(0.2, 0.2, 0.2)
		Bullet.TopSurface = "Smooth"
		Bullet.BottomSurface = "Smooth"
		Bullet.BrickColor = BrickColor.new("Dark stone grey")
		Bullet.CanCollide = false
		Bullet.CFrame = Gun.Handle.CFrame
		Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p)
  local v = Instance.new("BodyVelocity", Bullet)
		v.velocity = Bullet.CFrame.lookVector * 90
		v.maxForce = Vector3.new(math.huge, math.huge, math.huge)
	end

end

Everything is correct, but my Firing Projectile still won't fire. Can you help me? Thank you!

1 answer

✓ Accepted answer

You need to use an event in order to get the 'shoot()' function to work. I would recommend using UserInput, like so;

serv = game:GetService("UserInputService")
serv.InputBegan:connect(function(input)
	if serv.MouseEnabled then
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			shoot()
		end
	end
end)

I'd give a more through explanation of each line, but I'm on mobile. Still, hope this helps. :)

3 comments

0

I'd meant 'Shoot()' not 'shoot()', sorry!

0

Awesome thank you for your answer it really helped me! So If I want to use any player action next time, I use UserInput?

0

Glad I could help. And yep, you should. Here's a link to all of the properties of Userinput, just to show you what you can do with it. http://wiki.roblox.com/?title=API:Class/UserInputService

This discussion is preserved as it was. New answers, comments, and votes are closed.