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

How would I go about a debounce on the server side using Remote Events?

Asked by 4 years ago

So I made a tool where it spawns a brick but since I don't want people to spam it I wanted to put a debounce

I decided not to do it in the local script because if I did that exploiters can easily exploit it

So heres my Local Script


local Tool = script.Parent local Handle = Tool.Handle local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent Tool.Equipped:Connect(function(Mouse) Mouse.Button1Down:Connect(function()-- If Mouse is pressed RemoteEvent:FireServer() -- I fire Server end) end)

and my Server Script

local RemoteEvent = game:GetService("ReplicatedStorage").RemoteEvent

local CanFire = true

local ReloadTime = 999

RemoteEvent.OnServerEvent:Connect(function(player)

if CanFire == true then
    local part = Instance.new("Part")
    part.Parent = workspace
        CanFire = false
        wait(ReloadTime)
        CanFire = true


    end



end)

The problem is that if one person fires this remote the other person cannot fire the remote and has to wait 999 seconds before firing again

I want it that each person can fire it without affecting other people

like Filtering Enabled

0
I answered a question very similar to this yesterday. Look at my answer and the comment, because the comment mentions some things that should be changed. https://scriptinghelpers.org/questions/85830/how-do-i-make-my-debounce-for-remote-event-for-each-player-not-just-for-everyone Unhumanly 152 — 4y
0
2 days ago I mean. Unhumanly 152 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

You can use a cool down time. This may be different than what you mean!

wait(5) --Waits 5 seconds
0
Put it at the end of your script! imnoginglogin 0 — 4y
0
PUT EVERYTHING AFTER THE COOLDOWN TIMER BELOW IT imnoginglogin 0 — 4y
Ad
Log in to vote
0
Answered by
qChaos 86
4 years ago

I personally solve this issue by using a table debounce for each player's userid, let me know if you have any questions:

local CooldownTimer=5

local OnCooldown={}
local function Cooldown(UserId)
    OnCooldown[#OnCooldown+1]=UserId
    spawn(function()
        wait(CooldownTimer)
        for I=1,#OnCooldown do
            local CooldownedPlayer=OnCooldown[I]
            print(CooldownedPlayer)
            if CooldownedPlayer==UserId then
                table.remove(OnCooldown,I)
            end
        end
    end)
end
local function CheckIfOnCooldown(Player)
    local Passed=false
    for I=1,#OnCooldown do
        local CooldownedPlayer=OnCooldown[I]
        print(CooldownedPlayer)
        if CooldownedPlayer==Player.UserId then
            Passed=true
        end
    end
    return Passed
end

Answer this question