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
10 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 10 years ago
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)
0
It brought the ammo up to 12 instead of 10 and made the maxammo 0 again, and it broke the gun. acecateer 130 — 10y
0
Alright, i've edited my answer. Try that code. TheGuyWithAShortName 673 — 10y
Ad

Answer this question