Ok let me explain my problem. So,im attempting to make a RP gun that i wanna use for my game,and i'm stuck at the reloading part.

Once the bullet value reaches 0,the gun reloads with the need of pressing R But during that reload,if i click a few times,the ammo gets lowered after the reload

(Let's say the reload is 3 seconds,and the magazine has 15 bullets,if i click 5 times in 3 seconds,i will lose 5 bullets after the reload,and the muzzle flash nor sound plays)

(I commented some of the anim parts as i still dont have an anim for these parts)

game.ReplicatedStorage.Shoot.OnServerEvent:Connect(function(player) -- Event thingy
	
if not debounce then
	
Bullets = Bullets -1 -- Takes away 1 bullet after every shot
print(Bullets)

Shoot:Play() -- Shooting Sound
--local animTrack = Humanoid:LoadAnimation(Fire)
--animTrack:Play()

-- Muzzle Flash
FlashGui.Enabled = true
wait(0.1)
FlashGui.Enabled = false
			
end	

debounce = true
wait(1)
debounce = false -- Debounce1

-- Reload
if Bullets <1 then 
	script.Disabled = true
	script.Parent.Reload:Play()
	--local animtrack = Humanoid:LoadAnimation(ReloadAnim)
	--animTrack:Play()
	wait(1.7)
	Bullets = 15
	script.Disabled = false 
end

end)

Anyone know how to fix this? I'll explain better if you want me to.

13 comments

1

Indent

0

Does indenting really matter,or is it for aesthetic reasons?

0

Ah nevermind,it does play a role,i guess (i'll go and rewrite every line without removing the auto-indent now)

1

People indent their code for the sake of readability. If you are removing the automatic indents, don't do that. Your code is very messy.

0

Yeah,sometimes i hardly understand it myself

0

indenting is technically just for visual reasons but most people aren't going to help you if they can't read your code

0

i'm trying to improve readability,so hold on for a bit

0

Additionally, indentation makes it many times easier to debug code, for example if you're missing an end. https://developer.roblox.com/articles/Writing-Clean-Code

0

To try fixing your problem, it's likely on lines 25 and 31. You're having the script disable itself, and it cannot execute anymore because it's disabled. Have another script do it or don't do that at all, and stop them from shooting using another method.

0

I think that it's read-able now,all of my previous scripts are this messy,i should re-visit them someday

0

I mainly used the script disabling itself as i remembered it from a tutorial i watched some time ago,and my cousin told me to try debounce (that didn't work out so well)

0

on the Activated/MouseButton1Down event add a debounce before firing the Shoot remote. Ex: if not Reloading then ..

0

ok,i'll go and edit the script that fires the remote (it's in a separate script,so oof)