Problem With Server Side Debounce Per Player

I want to get a bool value named after a player’s UserId but it does not work saying that the instance simply does not exist. I tried getting the id to be a tostring(plr.UserId) variable but that still does not work. :man_shrugging:

If you have another way for server side, per player debounces, feel free to let me know to use it instead. :sweat_smile:

Any help is greatly appreciated!

Server Script Code
local repStorage = game:GetService("ReplicatedStorage")
local idfolder = workspace:WaitForChild("idFolder")

local debouncefolder = gameplay:WaitForChild("GrassDebounce")
local remotes = repStorage:WaitForChild("remotes")

local cd = 2

remotes.remoteEventOk.OnServerEvent:Connect(function(plr)
	
	local id = tostring(plr.UserId)
	local db = grssDb.id.Value
	local char = plr.Character
	local hum = char.Humanoid
	local floormat = hum.FloorMaterial

	
	if floormat == Enum.Material.Grass and not db then
		
			db = true		
			
			hum.WalkSpeed = 0
			hum.JumpPower = 0
		
			wait(cd)

			db = false
			hum.WalkSpeed = 19
			hum.JumpPower = 51
			
	end
			
end)
Local Script Code
local CAS = game:GetService("ContextActionService")
local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local idfolder = workspace:WaitForChild("idFolder")

local remotes = repStorage:WaitForChild("remotes")
local debouncefolder = idfolder:WaitForChild("GrassDebounce")
local plr = players.LocalPlayer

local cd = 2

local function groundTouch(actionName, state)
	
	local id = tostring(plr.UserId)
	local db = debouncefolder.id.Value
	
	if state == Enum.UserInputState.Begin and not db then
		
		remotes.remoteEventOk:FireServer()
		
		if plr.Character.Humanoid.FloorMaterial == Enum.Material.Grass then
			
			plr.Character.Humanoid.WalkSpeed = 0
			plr.Character.Humanoid.JumpPower = 0
			--print("touched grass")
			
			wait(cd)
			
			plr.Character.Humanoid.WalkSpeed = 19
			plr.Character.Humanoid.JumpPower = 51
			
		end

	end	
end



CAS:BindAction("TouchGround", groundTouch, false, Enum.KeyCode.E)

This is the server side script error.
image

This is the client side script error.
image

Please note that some names are not the same to protect my game as much as I can.

You’re trying to get the debounce object by the name “id”, but there’s nothing called “id” in the grssDb folder. Try using

grssDb[id].Value

Then it’ll try to find the actual id not the string “id” from grssDb

1 Like

I did it and now there are no errors, you can spam the button though without DB.

For a server side debounce per player you can simply use the table debounce technique.

Using value instances feels unnecessary unless you want to undo the debounce via another script.

3 Likes

Try using tables like dthecoolest told you, they’re much better for debounce from what I know, if you still face trouble let me know

1 Like

Trying it right now, it should work.

@Profituber @dthecoolest
Can I use a module script in repStorage and require it every time the funtions are called?

You could it’s still a table which you can put information in, but there is no need to require it every time the function is called as module scripts only run once so you could store what it returns in a local variable.

1 Like

Note that I’ll be using the module in 2 scripts?

That should be fine, but I don’t think adding to the table from a LocalScript would work so only add from the Server Script

1 Like

I may have been wrong, changes made to the table in the ModuleScript probably wont replicate to the LocalScript and vice versa

1 Like

So there can be a debounce only server side?

I’d just make a Per Player debounce on the server side with a table and a normal debounce on the LocalScript because the LocalScript doesn’t replicate to other clients.
The LocalScript should look something like this:

-- Your variables or whatever
local Debounce = false

local function groundTouch(actionName, state)
	
	if Debounce or state ~= Enum.UserInputState.Begin then return end

    Debounce = true

    remotes.remoteEventOk:FireServer()

    if plr.Character.Humanoid.FloorMaterial ~= Enum.Material.Grass then
        wait(2)
        Debounce = false
        return
    end

    plr.Character.Humanoid.WalkSpeed = 0
	plr.Character.Humanoid.JumpPower = 0
			
    wait(2)
		
	plr.Character.Humanoid.WalkSpeed = 19
	plr.Character.Humanoid.JumpPower = 51

    Debounce = false
end

-- The ContextActionService Bind
1 Like

Thank you, @Profituber @dthecoolest !
I just remade the whole debounce thing on the server side* and completely scrapped the client side system only firing the event!

*Using the method here .

Alright, Glad it worked out!
Have fun game deving.

1 Like