Debounce variable wont work for some reason

Alright so long story short I’ve tried making a script similar to this with a debounce variable that (In a nutshell) looks like this:
in a nutshell

This is the full thing however

Can you let me know why it doesn’t work? If you need more screenshots I can provide some
P.S There is nothing else in the script obstructing it’s function
P.P.S I know that there is a way I could do this more efficiently but I’m sticking with this

1 Like

Why aren’t you using variables for real.

1 Like

what do you mean by that? (I’m adding this to make the message long enough)

1 Like

Maybe you could try putting some prints in there and looking at the Output to see what is running.

1 Like

Like i say, Why aren’t you making use of variables. It’s much easier to work with and it also saves us time to read what you are trying to accomplish. And outside of using while true do loops. Use RunService instead.

1 Like

Yeah I tried that, the debounce doesn’t work and everything inside the if statement happens, also I printed the debounce variable and it started as true the first time but ended up as false even though it kept printing out

1 Like

I’m simplifying it later, do you have a solution at all?

1 Like

Could you send the code in text format since it would be easier to work with.

Eg.

local test = "hi"
print(test)
1 Like

Blockquote
while wait() do
script.Parent.VotePad1.SurfaceGui.Votes.Text = "Votes: ".. table.maxn(voted1)
script.Parent.VotePad2.SurfaceGui.Votes.Text = "Votes: ".. table.maxn(voted2)
script.Parent.VotePad1.SurfaceGui.Votes.Text = “”
script.Parent.VotePad1.Value.Value = table.maxn(voted1)
script.Parent.VotePad2.SurfaceGui.Votes.Text = “”
script.Parent.VotePad2.Value.Value = table.maxn(voted2)
if game.ReplicatedStorage.RoundValues.Voting.Value == false and debounce == true then
debounce = false
local randomnumber = math.random(1,maps)
script.Parent.Board1.Map.Value = maps[randomnumber]
script.Parent.Board1.SurfaceGui.Votes.Text = maps[randomnumber]
randomnumber = math.random(1,maps)
script.Parent.Board2.Map.Value = maps[randomnumber]
script.Parent.Board2.SurfaceGui.Votes.Text = maps[randomnumber]
–Making sure all maps are different
repeat
randomnumber = math.random(1,maps)
script.Parent.Board2.Map.Value = maps[randomnumber]
if script.Parent.Board2.Map.Value == script.Parent.Board1.Map.Value then
randomnumber = math.random(1,maps)
script.Parent.Board2.Map.Value = maps[randomnumber]
end
script.Parent.Board1.SurfaceGui.Votes.Text = script.Parent.Board1.Map.Value
script.Parent.Board2.SurfaceGui.Votes.Text = script.Parent.Board2.Map.Value
until script.Parent.Board2.Map.Value ~= script.Parent.Board1.Map.Value

if game.ReplicatedStorage.RoundValues.Voting.Value == false then
if script.Parent.VotePad1.Value.Value> script.Parent.VotePad2.Value.Value then
game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board1.Map.Value
else
if script.Parent.VotePad1.Value.Value < script.Parent.VotePad2.Value.Value then
game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board2.Map.Value
else
local a = math.random(1,2)
if a == 1 then
game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board1.Map.Value
else
game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board2.Map.Value
end
end
end
end
debounce = true
end

1 Like
while wait() do
	script.Parent.VotePad1.SurfaceGui.Votes.Text = "Votes: ".. table.maxn(voted1)
	script.Parent.VotePad2.SurfaceGui.Votes.Text = "Votes: ".. table.maxn(voted2)
	script.Parent.VotePad1.SurfaceGui.Votes.Text = ""
	script.Parent.VotePad1.Value.Value = table.maxn(voted1)
	script.Parent.VotePad2.SurfaceGui.Votes.Text = ""
	script.Parent.VotePad2.Value.Value = table.maxn(voted2)
	if game.ReplicatedStorage.RoundValues.Voting.Value == false and debounce == true then
		debounce = false
		local randomnumber = math.random(1,#maps)
		script.Parent.Board1.Map.Value = maps[randomnumber]
		script.Parent.Board1.SurfaceGui.Votes.Text = maps[randomnumber]
		randomnumber = math.random(1,#maps)
		script.Parent.Board2.Map.Value = maps[randomnumber]
		script.Parent.Board2.SurfaceGui.Votes.Text = maps[randomnumber]
		--Making sure all maps are different
		repeat		
			randomnumber = math.random(1,#maps)
			script.Parent.Board2.Map.Value = maps[randomnumber]
			if script.Parent.Board2.Map.Value == script.Parent.Board1.Map.Value then
				randomnumber = math.random(1,#maps)
				script.Parent.Board2.Map.Value = maps[randomnumber]
			end
			script.Parent.Board1.SurfaceGui.Votes.Text = script.Parent.Board1.Map.Value
			script.Parent.Board2.SurfaceGui.Votes.Text = script.Parent.Board2.Map.Value
		until script.Parent.Board2.Map.Value ~= script.Parent.Board1.Map.Value
			--
		if game.ReplicatedStorage.RoundValues.Voting.Value == false then
			if script.Parent.VotePad1.Value.Value> script.Parent.VotePad2.Value.Value then
				game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board1.Map.Value
			else
				if script.Parent.VotePad1.Value.Value < script.Parent.VotePad2.Value.Value then
					game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board2.Map.Value
				else
					local a = math.random(1,2)
					if a == 1 then
						game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board1.Map.Value
					else
						game.ReplicatedStorage.RoundValues.CurrentMap.Value = script.Parent.Board2.Map.Value
					end
				end
			end
		end
		debounce = true
	end
1 Like

Maybe i don’t understand what you mean but how does this not work?

local Debounce = false

local RunService = game:GetService("RunService")

function Test()
	if not Debounce then
		Debounce = true
		print(1)
		Debounce = false
	end
end

RunService.Heartbeat:Connect(Test)
2 Likes

Why do you think you need a debounce? Are there multiple scripts with this code running?

1 Like

I made this when I was exhausted and I forget what was going through my head

1 Like

I think I may use this format, thanks for the idea

2 Likes