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

Shots firing after the reload,How do i fix?

Asked by
BluZaw 5
5 years ago
Edited 5 years ago

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.

1
Indent TheEpicObbyCreator 32 — 5y
0
Does indenting really matter,or is it for aesthetic reasons? BluZaw 5 — 5y
0
Ah nevermind,it does play a role,i guess (i'll go and rewrite every line without removing the auto-indent now) BluZaw 5 — 5y
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. User#19524 175 — 5y
View all comments (9 more)
0
Yeah,sometimes i hardly understand it myself BluZaw 5 — 5y
0
indenting is technically just for visual reasons but most people aren't going to help you if they can't read your code User#22604 1 — 5y
0
i'm trying to improve readability,so hold on for a bit BluZaw 5 — 5y
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 User#19524 175 — 5y
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. User#19524 175 — 5y
0
I think that it's read-able now,all of my previous scripts are this messy,i should re-visit them someday BluZaw 5 — 5y
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) BluZaw 5 — 5y
0
on the Activated/MouseButton1Down event add a debounce before firing the Shoot remote. Ex: if not Reloading then .. hellmatic 1523 — 5y
0
ok,i'll go and edit the script that fires the remote (it's in a separate script,so oof) BluZaw 5 — 5y

Answer this question