Okay so first off here is how my system works.
I made a gun but theres one issue.
To simplify the system.
Click with gun on client
Fire remote event
For anti-cheat the remote event puts a boolvalue inside of the player for X amount of time. If the event is fired again while the boolvalue is inside of the player it will kick them.
To prevent the remote event from being fired twice on the client I do this after firing the remote event
local a = coroutine.wrap(function()
cantfire = true
repeat task.wait() until plr:FindFirstChild("insert name of boolvalue here")
repeat task.wait() until not plr:FindFirstChild("insert name of boolvalue here")
cantfire = false
end)
a()
Cantfire is obviously a variable that wont let the gun fire
Now the issue with this is that sometimes the script gets stuck on the first task.wait() loop and makes the gun unusable. Why is this and how can I fix it?
Hopefully I explained my issue well enough. If not feel free to ask any questions. Thank you for any help you may provide.
Hard to say without more context. Could you just post the whole client-side script at least? I fear you might’ve hidden the bug in your effort to simplify things.
Sounds like it will potentially add and remove the boolean before replicating to the player, instancing and destroying objects is very taxing. It might be better to just keep the boolValue and set it to true/false. You could repeat until plr.canFire.Value instead but then you might as well just use the plr.canFire.Value itself which will still be laggy and still incur a minimum time to fire based on ping which I believe you’re hitting and is pretty awful.
For quick firing guns I would just trust the client on fire rate. Maybe you should instead check when the player hits another and see if it is reasonable.
local function bvhandler(plr,bvname)
repeat
runservice.Heartbeat:Wait()
print('first yield')
until plr:FindFirstChild(bvname)
repeat
runservice.Heartbeat:Wait()
print("second yield")
until not plr:FindFirstChild(bvname)
end
Well that’s the thing if you want to check with the server every time they fire, you’re going to have to wait for the server. There isn’t an waitless way to ask the server anything
-- server example
RS.Moves.GlockHand.OnServerEvent:Connect(function(player: Player)
if player:GetAttribute("cantfire") then
kickplayer(player)
else
player:SetAttribute("cantfire", true)
task.wait(90)
player:SetAttribute("cantfire", false)
RS.Moves.GlockHand.OnServerEvent:FireClient(player)
end)