Server Debounce

I must be doing something really wrong because this is a huge issue that keeps popping up in my game, but i can’t really find any posts about it.

What do I do if a debounce is in a server script, to make it only affect each specific player?

(e.g. the player goes over a boost pad, the debounce changes to true for 2 seconds, but another player goes over the boost before the debounce is back to false so it doesn’t work for them).

This is a huge issue in many parts of my game so I was wondering if i was just being stupid and there’s an easy fix, or it’s something else entirely. Thanks!

You can create a table inside the script and insert the Players that are on cooldown in there
This would be an example:

local debounce = {}

local function doSomething(Player)
 if table.find(debounce,Player) then return end
 table.insert(debounce,Player)

 task.spawn(function()
 task.wait(cooldown)
 table.remove(debounce,table.find(debounce,Player))
 end)

 --Enter code here
end
1 Like
local db = true
local target = game.Players:WaitForChild("PlayerName")
local part = workspace:WaitForChild("Part")

part.Touched:Connect(function(hit)
	if hit.Parent == target.Character and db then
		db = false
        --
		task.wait(2)
		db = true
	end
end)

Sorry, not sure what you’re looking for here, there was no script to work from.
I guess you want just one person debounced..

This doesn’t solve his problem,. He wants individual debounce, also why did you even add PlayerRemoving or PlayerAdded into this?

What you wrote is still a “global debounce”, the part will be inaccessible for everyone else for 2 seconds when 1 player interacts with it.

also you can just use

task.delay(cooldown,function()
 table.remove(debounce,table.find(debounce,Player))
end)

just a bit cleaner I guess

(just use what @Fietowski suggested, that’s the best solution)

2 Likes

ithink there is many ways to solve that issue you can use @sie dev_sie way or add boolvalue called debounce to player whene he join the game and change it whene ever you want

local plrDebounce= {}
local debounceTime = 1

local function doSomething(plr : Player)
	if plrDebounce[plr.UserId] then return end
	plrDebounce[plr.UserId] = true
	--something...

	task.delay(1, function()
		plrDebounce[plr.UserId] = nil
	end)
end```

Putting this at the end of the script may not always work as intended, for example if the main script inside the function yields something.

I guess yeah but how else would you do it

By putting it right at the start, it creates a new thread so it won’t hinder the rest of the function.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.