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

Making a gun shoot forwards?

Asked by 5 years ago

I'm trying to create a gun, and I know a little bit of what I need to. I'm using LookVector, but I just learned it today so I don't know much about it. This is also the first time I've even made a gun, so sorry that it's so bad.

--Sorry in advance for the messy code and lack of knowledge on CFrame (and other things), it's my first time making a gun.
local Tool = script.Parent
local FireEvent = game.ReplicatedStorage.FireEvent --FireEvent is a RemoteEvent
local FirePoint = Tool.BulletPoint
local BulletSpeed = 200
local Damage = 100 --This goes...Somewhere, but where?
local Mouse = game.Players.LocalPlayer:GetMouse()
local GunGui = Tool.GunGui
local Mag = Tool.Mag
local Ammo = Tool.Ammo
local ReloadTime = 1

function Ammo()
    GunGui.Mag.Text = Mag.Value
    GunGui.Ammo.Text = Ammo.Value
end

function Reload()
    game:GetService("UserInputService").InputBegan:connect(function(Key, Chatting)
    if Key.KeyCode == Enum.KeyCode.R and Chatting == false then
        if Equipped == true then
            wait(ReloadTime)
            if Ammo.Value > 0 then
            Mag.Value = 2
            Ammo.Value = Ammo.Value - 2
            end
        end
end

local Bullet = Instance.new("MeshPart",workspace) --Dunno where to put this or how to make it work
Bullet.MeshId = "rbxassetid://430333724"
Bullet.BrickColor = BrickColor.new("Cocoa")

local AttachmentA = Instance.new("Attachment",Bullet)
AttachmentA.Position = Vector3.new(0,.1,0) --Not sure if I'm doing most of this right

local AttachmentB = Instance.new("Attachment",Bullet)
AttachmentB.Position = Vector3.new(0,0,0)  --Same here

local Trail = Instance.new("Trail",Bullet)
Trail.Attachment0 = AttachmentA
Trail.Attachment1 = AttachmentB
Trail.Color = BrickColor.new("Institutional white")
Trail.Transparency = .2

Mouse.Button1Click:connect(function()
function Shoot() 
    if Mag > 0 then
    FireEvent:FireServer() 
    Bullet.CFrame = FirePoint.Position --I'm pretty sure this is wrong, but I can't tell what is wrong with it.
    Bullet.CFrame.LookVector * BulletSpeed --I don't know what went wrong here.
    end
    end
end)

Thanks for any help or advice you have.

Answer this question