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 8 years ago

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

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

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. :)

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

Answer this question