Here is the code I'm going to sleep I will see what you guys say tomorrow.
reloading=(false) function reload(key) if (reloading==(true)) then return end reloading=(true) key = (key:lower()) if(key==("e")) then if(tool.Ammo.Value==(not 0)) then return end -- I believe the problem is here, can still reload animation=(tool.Parent.Humanoid:LoadAnimation(tool.Animation)) animation:Play() wait((3)) tool.Ammo.Value=(20) reloading=(false) end end mouse.KeyDown:connect(reload)
Ammo
is not equal to 0. You're not doing that in reality.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
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 --OR-- if tool.Ammo.Value > 0 then return end
local reloading = false -- use local variables local function reload(key, gpe) if reloading then return end -- you wouldn't need to check == true if gpe then return end -- if chatting or something where text is being processed reloading = true -- we are reassigning the first reloading variable, don't add local if key.KeyCode == Enum.KeyCode.E then -- We will instead use UserInputService as KeyDown is an inconsistent way to get user input and is deprecated. if tool.Ammo.Value > 0 then return end -- fixed 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)