Ad
Log in to vote
0

The else statement wont run?

Asked by 14 days ago
local Damage = game.ReplicatedStorage.Guns.Colt.Damage.Value
local Ammo = game.ReplicatedStorage.Guns.Colt.Ammo.Value
local MaxAmmo = game.ReplicatedStorage.Guns.Colt.MaxAmmo.Value
local AmmoReloadTime = game.ReplicatedStorage.Guns.Colt.ReloadTime.Value

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Handle = script.Parent.Handle
local Colt = script.Parent

script.Parent.Activated:Connect(function()
print("activated")
    if Ammo ~= 0 then
        print('enough ammo')
        game.ReplicatedStorage.Guns.Colt.Ammo.Value = game.ReplicatedStorage.Guns.Colt.Ammo.Value - 1 
        print('removed ammo')
        if Mouse.Target~= nil then
            if Mouse.Target.Parent:FindFirstChild('Humanoid') then
                print('targetted player')
                game.ReplicatedStorage.Guns.Fire:FireServer(Damage, Ammo, MaxAmmo, Mouse, Mouse.Target, AmmoReloadTime)
            end 
        end 
    else
        print('no ammo')

    end 
end)

iin the else statement, it never prints or does what i put in the else statement. the ammo number goes to negative and still damages players what do i do to make it stop when the ammo is = 0

2 answers

Log in to vote
0
Answered by
ellxiac 78
14 days ago

You should check if the player has more than 0 ammo, so you would need to use ">" instead of "~=" in line 14.

0
ellxiac, i already tried that before, it doesn't work. InspireWithFun 7 — 14d
Ad
Log in to vote
0
Answered by 13 days ago

It has been fixed, i just needed to remove the .Value from the variable and put it in the if statement line

Answer this question