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

Help with making this automatic gun less buggy?

Asked by
niroqeo 123
4 years ago
Edited 4 years ago

I need help with making this automatic gun less buggy(what I mean by buggy is it may fire faster for a second then back to normal).

mouse.Button1Down:connect(function()
    mouseDown = true
   if auto then
    while mouseDown do
        wait()
        if cooldown == false then
            cooldown = true
            fire()
            wait(fireRate)
            cooldown = false
        end
    end
else
     if cooldown == false then
    fire()
    cooldown = true
    wait(fireRate)
    cooldown = false
    end
end
end)

Thanks!

1 answer

Log in to vote
1
Answered by 4 years ago

It feels buggy because you have a wait() before anything happens when you click, thus there is an unnecessary delay between clicking and the fire() function getting called. To make the gun feel more responsive this wait() should be placed after the if statement has happened.

while mouseDown do
    if cooldown == false then
        cooldown = true
        fire()
        wait(fireRate)
        cooldown = false
    end
    wait()
end

Now, more importantly, you definitely should be using RunService.Heartbeat:Wait() (https://developer.roblox.com/en-us/api-reference/class/RunService) because wait() is only able to delay the script 1/30th of a second while using what I put above allows you to have a delay of half that.

If the script you provided isn't a localscript, it needs to be to use the renderstepped wait. There is no way to keep the script a non-local and have a smaller delay.

0
It's not firing slower.. It's firing faster, or it shoots 2 at once... niroqeo 123 — 4y
0
Good Guy Here Take Up-vote and Gold ^_^ ???? royaltoe 5144 — 4y
0
emoji didnt send idk y royaltoe 5144 — 4y
0
Thanks, I didn't know that RunService existed and I'm grateful you showed it to me. I also fixed the buggyness by making it a repeat until loop. niroqeo 123 — 4y
0
oh nice, I apologize for a late response GriffthouBiff 147 — 4y
Ad

Answer this question