Hello, I have made a gun that works but when I reload I can spam the reload key and it's annoying because if you ever happend to click it twice youre ammo decreases alot.

function onKeyDown(key, mouse)

	if key:lower() == "r" then
		if script.Parent.Ammo.Value ~= script.Parent.MaxAmmo.Value then
			if (not reloading) then return end
			animtrack:Play()
			local reloadsound = script.Parent.Handle:FindFirstChild("RLD")
			if reloadsound then 
				reloadsound:Play()
			end
			enabled = false
			script.Parent.VisibleB.Value = true
			script.Parent.StringValue.Value = "Reloading"
			mouse.Icon = "http://www.roblox.com/asset/?id=70288585"
			script.Parent.Handle.RLD:play()
			wait(0.7)
			script.Parent.Bolt1A.Transparency = 1
			script.Parent.Bolt1.Transparency = 0
			repeat script.Parent.StringValue.Value = "Reloading" script.Parent.Ammo.Value = script.Parent.Ammo.Value + 3 script.Parent.StringValue.Value = "Reloading" until script.Parent.Ammo.Value >= script.Parent.MaxAmmo.Value
			script.Parent.Ammo.Value = script.Parent.MaxAmmo.Value
			script.Parent.Munizioni.Value = script.Parent.Munizioni.Value - 1
			if script.Parent.Munizioni.Value == 0 then
				reloading = false
			end
			enabled = true
			cloneGUI.Frame.Ammo.Text = script.Parent.Ammo.Value
			cloneGUI.Frame.Mags.Text = script.Parent.Munizioni.Value
			script.Parent.VisibleB.Value = false
			mouse.Icon = "http://www.roblox.com/asset/?id=70288585"
		end
	end

take note that reloading = true

Can someone help me out please?

1 comment

0

Fixed it, had to put "wait(0,7)" (line 16) into line 24-25.