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.
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.
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
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.
So ive tried both ways but still have the issue. Anything else I can do?
Is the server sided script inside the tool?
heres how my gun is set up
it has the two scripts I screenshotted earlier
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)
Yeah you could use time difference from when it was last fired.
I accidentally screenshotted the wrong local script
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
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)
for the timeFired argument you can pass in tick()
Thanks for all your help! I got it to work right.