I need help making a debounce for multiple scripts

  1. What do you want to achieve?
    A main debounce that when i change its value in a script, it actually changes the main debounce value.

  2. What is the issue? Include screenshots / videos if possible!
    The debounce i have, seems to make many copies that when i change it in a script, it changes only for that script.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

  • I tried making the debounce in a Module script and require it in other Scripts but it seems to make a new copy for every script i require it in.

  • Also tried to make a boolvalue and place it in Workspace or ReplicatedStorage, but still got the same issue. When i change the value in a script it doesn’t change the main value in Workspace / RS.

If its not clear enough

  • if i have 2 scripts and 1 boolValue in workspace. I referenced it in both scripts. In the 1st Script i changed the value to false while it was true. I printed the boolValue in the other script [With a wait so it executes after it changes] but it prints True.

Could you please provide the code or an example of how you’re referencing and changing the bools value.

I would add a bool value into replicated storage and rename it Debounce then use this code below to reference it in both scripts:

local debounce = false

if game.ReplicatedStorage.Debounce.Value == true then
debounce = true
--code for debounce when debounce = true--
elseif game.ReplicatedStorage.Debounce.Value == false then
debounce = false
--code for when debounce = false--
end

I hope this helps, although if you have tried it before then I am sorry.

1 Like

There is a boolValue in Replicated Stroage

-- How i reference it.
local debounce = game:GetService("ReplicatedStorage").debounce

-- How i change the boolValue.
debounce = false

That didn’t solve its still the same problem sadly. Thanks that you have tried.

Doing

local debounce = game:GetService("ReplicatedStorage").debounce
debounce = false

will only change the variable inside the script

you always want to access and change the value object’s Value property directly as shown here

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

debounce.Value = false
local debounce = game:GetService("ReplicatedStorage").debounce

if not debounce.Value then
   debounce.Value = true
end
2 Likes

Thank you so much. That fixed my problem.

2 Likes