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

Why is my gun refusing to shoot?

Asked by
Mr_Unlucky 1085 Moderation Voter
6 years ago
Edited 6 years ago

Basically, I want my gun to shoot, but it refuses to! There are no errors too.

local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Tool = script.Parent
local Animation = nil
local SettingsFolder = Tool.Settings
local MagSize = SettingsFolder.MagSize
local MagsLeft = SettingsFolder.MagsLeft
local CurrentBullets = SettingsFolder.CurrentBullets
local Damage = SettingsFolder.Damage
local MouseDown = false
local IsReloading = false
local IsEquipped = false
local CanShoot = true
local Mouse = game.Players.LocalPlayer:GetMouse()

Tool.Equipped:Connect(function()
    Animation = Humanoid:LoadAnimation(game.ReplicatedStorage.AK80_Hold)
    Animation:Play()
    IsEquipped = true
end)

Tool.Unequipped:Connect(function()
    Animation:Stop()
    IsEquipped = false
end)

Tool.Activated:Connect(function()
    MouseDown = true
    repeat
        wait(0.01)
        Fire()
    until MouseDown == false
end)

Tool.Deactivated:Connect(function()
    MouseDown = false
end)

function Reload()
    IsReloading = true
    Tool.Reload:Play()
    Animation:Stop()
    Animation = Humanoid:LoadAnimation(game.ReplicatedStorage.AK80_Reload)
    Animation:Play()
    wait(2.27)
    CurrentBullets.Value = MagSize.Value
    MagsLeft.Value = MagsLeft.Value - MagSize.Value
    Animation:Stop()
    Animation = Humanoid:LoadAnimation(game.ReplicatedStorage.AK_Hold)
    Animation:Play()
    IsReloading = false
end

function Fire()
    if IsEquipped == true then
        if IsReloading == false then
            if CanShoot == true then
                if CurrentBullets.Value == not 0 then
                    local ray = Ray.new(Tool.Handle.CFrame.p, (Mouse.Hit.p - Tool.Handle.CFrame.p).unit * 300)
                    local touch, position = workspace:FindPartOnRay(ray, game.Players.LocalPlayer.Character, false, true)
                    local trace = Instance.new("Part")
                    trace.Anchored = trace
                    trace.CanCollide = false
                    trace.Transparency = 0.5
                    trace.BrickColor = BrickColor.new("Electric blue")
                    trace.Material = Enum.Material.Neon
                    local distance = (Tool.Handle.CFrame.p + Vector3.new(0,0.6,0) - position).magnitude
                    trace.Size = Vector3.new(0, 0, distance)
                    trace.CFrame = CFrame.new(Tool.Handle.CFrame.p + Vector3.new(0,0.3,0), position) * CFrame.new(0, 0, -distance / 2)
                    trace.Parent = workspace
                    wait(0.1)
                    trace:Destroy()
                    Tool.Fire:Play()
                    CurrentBullets.Value = CurrentBullets.Value - 1
                    if touch then
                        local humanoid = touch.Parent:FindFirstChild("Humanoid")
                        if not humanoid then
                            humanoid = touch.Parent.Parent:FindFirstChild("Humanoid")
                        end
                        if humanoid then
                            humanoid:TakeDamage(Damage.Value)

                elseif CurrentBullets.Value == 0 and IsReloading == false and MagsLeft == not 0 then
                    Reload()
                end                 
                end
                end
            end
        end
    end
end
0
In lines 57 and 82, you’re converting 0 to false. User#19524 175 — 6y
0
Is the gun not shooting in studio, or ingame, or both? Talveka 31 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

game.Players.LocalPlayer.Character:WaitForChild("Humano

Second line,maybe you didnt write "Humanoid" well

Ad
Log in to vote
0
Answered by
Talveka 31
6 years ago
Edited 6 years ago

If your gun shoots in studio while testing, but not ingame, then it might be an FE issue. In FE, things like Instance.new wont go through, so you're going to have to use a RemoteEvent. Here's a tutorial on RemoteEvent; Tutorial

Answer this question