Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Firing Projectile Isn't Working?

Asked by 9 years ago

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

01Player = game.Players.LocalPlayer
02 
03Gun = script.Parent
04 
05Ammo = 5
06 
07mouse = Player:GetMouse()
08 
09function Shoot()
10 
11    if Ammo > 0 then
12        local Bullet = Instance.new("Part", workspace)
13        game.Debris:addItem(Bullet, 2)
14        Bullet.Shape = "Ball"
15        Bullet.Size = Vector3.new(0.2, 0.2, 0.2)
View all 27 lines...

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

1 answer

Log in to vote
2
Answered by
saenae 318 Moderation Voter
9 years ago

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

1serv = game:GetService("UserInputService")
2serv.InputBegan:connect(function(input)
3    if serv.MouseEnabled then
4        if input.UserInputType == Enum.UserInputType.MouseButton1 then
5            shoot()
6        end
7    end
8end)

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

0
I'd meant 'Shoot()' not 'shoot()', sorry! saenae 318 — 9y
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? GreekGodOfMLG 244 — 9y
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 saenae 318 — 9y
Ad

Answer this question