Help with gun shooting when it shouldnt be able to

I have a gun made but the issue is if you use an autoclicker or even just click really fast it can bypass the canshoot system and just shoot really fast. It just breaks the whole canshoot system for few seconds. That as you might guess is very bad and I need help fixing it. If anyone could give me some ideas that would be great.


2 Likes

I would probably do the checking on the server side script. Since anyone could just fire that event, and it would shoot without any checks.

3 Likes

Put the variable canshoot = false right after you activate the tool.

and that should be it I believe!

if canshoot == true then
   canshoot = false

--... your code
end
2 Likes

The way he did is also fine since he adds a wait after the whole if statement and then resets the canshoot variable back to true. (However, if there is any errors, it would not reach line 32, then canShoot would never turn to false.) For that and several other reasons and simplicity I would also do what @sky10 suggested.

2 Likes

So ive tried both ways but still have the issue. Anything else I can do?

1 Like

Is the server sided script inside the tool?

2 Likes

heres how my gun is set up
it has the two scripts I screenshotted earlier

image

1 Like

I would do something like this on the server script.

local canShoot = true
script.Parent.Parent.FireGun.OnServerEvent:Connect(function(player,mouse)
    if canShoot then
        canShoot = false
        --Your code here
        wait(3)
        canShoot = true
    end
end)

2 Likes

Still have the same issue. anything else?



1 Like

Yeah you could use time difference from when it was last fired.

2 Likes

I accidentally screenshotted the wrong local script

1 Like

Here

local deBounce = true

	if deBounce == true then
		deBounce = false


--...code
			wait(3)
		deBounce = true
	end

the

			wait(3)
		deBounce = true

goes inside the if deBounce == true then statement

2 Likes
local lastFired = nil

function Shoot()
	--Shoot code here
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, timeFired)
	local shoot
	if lastFired == nil then
		Shoot()
		lastFired = timeFired
	else
		if timeFired - lastFired >= 3 then
			Shoot()
			lastFired = timeFired
		end
	end
end)
2 Likes

for the timeFired argument you can pass in tick()

2 Likes

Thanks for all your help! I got it to work right.

2 Likes