Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problem with reloading gun?

So I tried making it so that if they press r it would take 10 away from the max ammo and bring their ammo back up. But when I did the code below it infinitely added ammo and didn't stop adding at 10 it just kept going and went into the hundreds. It also took all of the max ammo.

mouse.KeyDown:connect(function(key) if key == "r" and maxammo.Value >0 then maxammo.Value = maxammo.Value - 10 repeat wait(0.1) ammo.Value = ammo.Value + 1 until ammo.Value == 10 end end)

1 answer

mouse.KeyDown:connect(function(key) if key:lower() == "r" and maxammo.Value >0 then maxammo.Value = maxammo.Value - 10 repeat wait(0.1) ammo.Value = ammo.Value + 1 until ammo.Value >= 10 end end)

This might fix it, but I'm not sure.

EDIT

Try this:

mouse.KeyDown:connect(function(key) 
if key:lower() == "r" and maxammo.Value >0 then
while ammo.Value<10 do 
ammo.Value = ammo.Value + 1 
maxammo.Value=maxammo.Value-1
wait(0.1)
end 
end
end)

2 comments

0

It brought the ammo up to 12 instead of 10 and made the maxammo 0 again, and it broke the gun.

0

Alright, i've edited my answer. Try that code.

This discussion is preserved as it was. New answers, comments, and votes are closed.