###The problem with your script is on line 7. You're trying to check if the Ammo is not equal to 0. You're not doing that in reality.
#Booleans
###All scripters should know about booleans. They are true or false. However, there are truthy and falsey values. true is obviously a truthy value and false a falsey. But numbers and strings, since they are not nil or false, they are treated as true/truthy. So what line 7 is basically doing is:
if tool.Ammo.Value == false then
###You're checking if its value is equal to false. But according to that script of yours it is an IntValue or a NumberValue. To fix that, you can check if the value is greater than 0, or just not equal to 0 in general.
if tool.Ammo.Value ~= 0 then return end
if tool.Ammo.Value > 0 then return end
###Final product:
local reloading = false
local function reload(key, gpe)
if reloading then return end
if gpe then return end
reloading = true
if key.KeyCode == Enum.KeyCode.E then
if tool.Ammo.Value > 0 then return end
local animation = tool.Parent.Humanoid:LoadAnimation(tool.Animation)
animation:Play()
wait(3)
tool.Ammo.Value = 20
reloading = false
end
end
game:GetService("UserInputService").InputBegan:Connect(reload)
###The indentations in your code are worth noting. Don't remove the indentations that Studio gives you. It helps you and other readers to read your code better. Learn on writing clean code here
5 comments
0 Um, why exactly did you put the "not 0" in Line #7? Also, keyDown is deprecated try using this instead: http://robloxdev.com/articles/Keyboard-Input-Methods
I believe OP did that to check if the bullets were not equal to 0. However it was done wrong lol
@incapaz right its totally wrong. I'm still confused on why he would want the bullets to not equal 0 if he is trying to play a reload animation...
No, OP wants to check if the bullets are not equal to zero, to stop the function. He wants a gun that will only reload if the bullet amount is zero.
@incapaz Oh snap you're right, I didn't see the return.