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

Problem with reloading gun?

Asked by
acecateer 130
11 years ago

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

Log in to vote
0
Answered by 11 years ago
1mouse.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:

1mouse.KeyDown:connect(function(key)
2if key:lower() == "r" and maxammo.Value >0 then
3while ammo.Value<10 do
4ammo.Value = ammo.Value + 1
5maxammo.Value=maxammo.Value-1
6wait(0.1)
7end
8end
9end)
0
It brought the ammo up to 12 instead of 10 and made the maxammo 0 again, and it broke the gun. acecateer 130 — 11y
0
Alright, i've edited my answer. Try that code. TheGuyWithAShortName 673 — 11y
Ad

Answer this question