It is suppose to turn back to false so the player can vote again, but instead it stays true instead of turning back to false.
I’ve tried moving the debounce, seeing if return does anything in the function, and tried other things to make it work but the error keeps occurring.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local repstore = game:GetService("ReplicatedStorage")
local Debounce = false
local gamePassID = gamepass
local Events = game:GetService("ReplicatedStorage").Events
local MapVoteEvent = Events.MapVote
local hasPass = false
local Mapvoting = script.Parent
local Pads = Mapvoting.VotePads
local MapVote = Mapvoting.MapVote
local Board = Mapvoting.VoteBoards
local Images = Board.Images
local Names = Board.Names
local Canvote = false
local OtherDebounce = false
local maps =
{
map1 = [231]
map2 = [anothernumber]
map3 = [AnotherNumber]
}
MapVoteEvent.OnInvoke = function(WaitTime,Lenght)
MapVote.Vote1.Votes:ClearAllChildren()
MapVote.Vote2.Votes:ClearAllChildren()
MapVote.Vote3.Votes:ClearAllChildren()
MapVote.Vote1.VotedGui.VotedAmount.Text = "0"
MapVote.Vote2.VotedGui.VotedAmount.Text = "0"
MapVote.Vote3.VotedGui.VotedAmount.Text = "0"
Images.MapImage1.MapGui.MapImage.ImageTransparency = 1
Images.MapImage2.MapGui.MapImage.ImageTransparency = 1
Images.MapImage3.MapGui.MapImage.ImageTransparency = 1
Names.MapName1.MapNameGui.MapName.Text = ""
Names.MapName2.MapNameGui.MapName.Text = ""
Names.MapName3.MapNameGui.MapName.Text = ""
wait(WaitTime)
local keysTable = {}
for key, value in pairs(maps) do
table.insert(keysTable, key)
end
wait()
local randomKey1 = keysTable[math.random(#keysTable)]
local mapChosen1 = maps[randomKey1]
local randomKey2, mapChosen2
repeat
wait()
randomKey2 = keysTable[math.random(#keysTable)]
mapChosen2 = maps[randomKey2]
until mapChosen2 ~= mapChosen1
local randomKey3, mapChosen3
repeat
wait()
randomKey3 = keysTable[math.random(#keysTable)]
mapChosen3 = maps[randomKey3]
until mapChosen3 ~= mapChosen1 and mapChosen3 ~= mapChosen2
Images.MapImage1.MapGui.MapImage.ImageTransparency = 0
Images.MapImage2.MapGui.MapImage.ImageTransparency = 0
Images.MapImage3.MapGui.MapImage.ImageTransparency = 0
Images.MapImage1.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen1
Images.MapImage2.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen2
Images.MapImage3.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen3
Names.MapName1.MapNameGui.MapName.Text = randomKey1
Names.MapName2.MapNameGui.MapName.Text = randomKey2
Names.MapName3.MapNameGui.MapName.Text = randomKey3
Canvote = true
function onPadTouched(touch, pad)
print(Debounce)
if not Debounce then
if Canvote == false then
return
end
Debounce = true
print(Debounce)
if game.Players:GetPlayerFromCharacter(touch.Parent) then
if MapVote.Vote1.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
for i, Vote in pairs(MapVote.Vote1.Votes:GetChildren()) do
if Vote.Name == game.Players:GetPlayerFromCharacter(touch.Parent).Name then
Vote:Destroy()
end
end
end
if MapVote.Vote2.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
for i, Vote in pairs(MapVote.Vote2.Votes:GetChildren()) do
if Vote.Name == game.Players:GetPlayerFromCharacter(touch.Parent).Name then
Vote:Destroy()
end
end
end
if MapVote.Vote3.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
for i, Vote in pairs(MapVote.Vote3.Votes:GetChildren()) do
if Vote.Name == game.Players:GetPlayerFromCharacter(touch.Parent).Name then
Vote:Destroy()
end
end
end
local touchVal = Instance.new("StringValue")
touchVal.Name = game.Players:GetPlayerFromCharacter(touch.Parent).Name
touchVal.Parent = pad.Votes
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(Players:GetPlayerFromCharacter(touch.Parent).UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
local touchVal2 = Instance.new("StringValue")
touchVal2.Name = game.Players:GetPlayerFromCharacter(touch.Parent).Name
touchVal2.Parent = pad.Votes
end
MapVote.Vote1.VotedGui.VotedAmount.Text = #MapVote.Vote1.Votes:GetChildren()
MapVote.Vote2.VotedGui.VotedAmount.Text = #MapVote.Vote2.Votes:GetChildren()
MapVote.Vote3.VotedGui.VotedAmount.Text = #MapVote.Vote3.Votes:GetChildren()
wait(0.1)
Debounce = false
end
end
end
wait(Lenght)
Canvote = false
if Debounce then
Debounce = false
end
local highestVoted
for i, pad in pairs(MapVote:GetChildren()) do
if not highestVoted then highestVoted = pad end
if #pad.Votes:GetChildren() > #highestVoted.Votes:GetChildren() then
highestVoted = pad
elseif #pad.Votes:GetChildren() == #highestVoted.Votes:GetChildren() then
local mapsToChoose = {pad, highestVoted}
wait()
highestVoted = mapsToChoose[math.random(#mapsToChoose)]
end
end
local mapName = Names["MapName" .. string.gsub(highestVoted.Name, "Vote", "")].MapNameGui.MapName.Text
MapVote.Vote1.VotedGui.VotedAmount.Text = "0"
MapVote.Vote2.VotedGui.VotedAmount.Text = "0"
MapVote.Vote3.VotedGui.VotedAmount.Text = "0"
Images.MapImage1.MapGui.MapImage.ImageTransparency = 1
Images.MapImage2.MapGui.MapImage.ImageTransparency = 1
Images.MapImage3.MapGui.MapImage.ImageTransparency = 1
Names.MapName1.MapNameGui.MapName.Text = ""
Names.MapName2.MapNameGui.MapName.Text = ""
Names.MapName3.MapNameGui.MapName.Text = ""
Images.MapImage1.MapGui.MapImage.Image = ""
Images.MapImage2.MapGui.MapImage.Image = ""
Images.MapImage3.MapGui.MapImage.Image = ""
print(mapName)
return mapName
end
Pads.VotePad1.Touched:Connect(function(touch)
onPadTouched(touch, MapVote.Vote1)
end)
Pads.VotePad2.Touched:Connect(function(touch)
onPadTouched(touch, MapVote.Vote2)
end)
Pads.VotePad3.Touched:Connect(function(touch)
onPadTouched(touch, MapVote.Vote3)
end)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local repstore = game:GetService("ReplicatedStorage")
local Debounce = false
local gamePassID = gamepass
local Events = game:GetService("ReplicatedStorage").Events
local MapVoteEvent = Events.MapVote
local hasPass = false
local Mapvoting = script.Parent
local Pads = Mapvoting.VotePads
local MapVote = Mapvoting.MapVote
local Board = Mapvoting.VoteBoards
local Images = Board.Images
local Names = Board.Names
local Canvote = false
local OtherDebounce = false
local maps =
{
map1 = [231]
map2 = [anothernumber]
map3 = [AnotherNumber]
}
MapVoteEvent.OnInvoke = function(WaitTime,Lenght)
MapVote.Vote1.Votes:ClearAllChildren()
MapVote.Vote2.Votes:ClearAllChildren()
MapVote.Vote3.Votes:ClearAllChildren()
MapVote.Vote1.VotedGui.VotedAmount.Text = "0"
MapVote.Vote2.VotedGui.VotedAmount.Text = "0"
MapVote.Vote3.VotedGui.VotedAmount.Text = "0"
Images.MapImage1.MapGui.MapImage.ImageTransparency = 1
Images.MapImage2.MapGui.MapImage.ImageTransparency = 1
Images.MapImage3.MapGui.MapImage.ImageTransparency = 1
Names.MapName1.MapNameGui.MapName.Text = ""
Names.MapName2.MapNameGui.MapName.Text = ""
Names.MapName3.MapNameGui.MapName.Text = ""
wait(WaitTime)
local keysTable = {}
for key, value in pairs(maps) do
table.insert(keysTable, key)
end
wait()
local randomKey1 = keysTable[math.random(#keysTable)]
local mapChosen1 = maps[randomKey1]
local randomKey2, mapChosen2
repeat
wait()
randomKey2 = keysTable[math.random(#keysTable)]
mapChosen2 = maps[randomKey2]
until mapChosen2 ~= mapChosen1
local randomKey3, mapChosen3
repeat
wait()
randomKey3 = keysTable[math.random(#keysTable)]
mapChosen3 = maps[randomKey3]
until mapChosen3 ~= mapChosen1 and mapChosen3 ~= mapChosen2
Images.MapImage1.MapGui.MapImage.ImageTransparency = 0
Images.MapImage2.MapGui.MapImage.ImageTransparency = 0
Images.MapImage3.MapGui.MapImage.ImageTransparency = 0
Images.MapImage1.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen1
Images.MapImage2.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen2
Images.MapImage3.MapGui.MapImage.Image = "rbxassetid://" .. mapChosen3
Names.MapName1.MapNameGui.MapName.Text = randomKey1
Names.MapName2.MapNameGui.MapName.Text = randomKey2
Names.MapName3.MapNameGui.MapName.Text = randomKey3
Canvote = true
function onPadTouched(touch, pad)
print(Debounce)
if not Debounce then
if Canvote == false then
return
end
Debounce = true
print(Debounce)
if game.Players:GetPlayerFromCharacter(touch.Parent) then
if MapVote.Vote1.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
for i, Vote in pairs(MapVote.Vote1.Votes:GetChildren()) do
if Vote.Name == game.Players:GetPlayerFromCharacter(touch.Parent).Name then
Vote:Destroy()
end
end
end
if MapVote.Vote2.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
for i, Vote in pairs(MapVote.Vote2.Votes:GetChildren()) do
if Vote.Name == game.Players:GetPlayerFromCharacter(touch.Parent).Name then
Vote:Destroy()
end
end
end
if MapVote.Vote3.Votes:FindFirstChild(game.Players:GetPlayerFromCharacter(touch.Parent).Name) then
for i, Vote in pairs(MapVote.Vote3.Votes:GetChildren()) do
if Vote.Name == game.Players:GetPlayerFromCharacter(touch.Parent).Name then
Vote:Destroy()
end
end
end
local touchVal = Instance.new("StringValue")
touchVal.Name = game.Players:GetPlayerFromCharacter(touch.Parent).Name
touchVal.Parent = pad.Votes
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(Players:GetPlayerFromCharacter(touch.Parent).UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
local touchVal2 = Instance.new("StringValue")
touchVal2.Name = game.Players:GetPlayerFromCharacter(touch.Parent).Name
touchVal2.Parent = pad.Votes
end
MapVote.Vote1.VotedGui.VotedAmount.Text = #MapVote.Vote1.Votes:GetChildren()
MapVote.Vote2.VotedGui.VotedAmount.Text = #MapVote.Vote2.Votes:GetChildren()
MapVote.Vote3.VotedGui.VotedAmount.Text = #MapVote.Vote3.Votes:GetChildren()
end
end
wait(0.1)
Debounce = false
end
wait(Lenght)
Canvote = false
if Debounce then
Debounce = false
end
local highestVoted
for i, pad in pairs(MapVote:GetChildren()) do
if not highestVoted then highestVoted = pad end
if #pad.Votes:GetChildren() > #highestVoted.Votes:GetChildren() then
highestVoted = pad
elseif #pad.Votes:GetChildren() == #highestVoted.Votes:GetChildren() then
local mapsToChoose = {pad, highestVoted}
wait()
highestVoted = mapsToChoose[math.random(#mapsToChoose)]
end
end
local mapName = Names["MapName" .. string.gsub(highestVoted.Name, "Vote", "")].MapNameGui.MapName.Text
MapVote.Vote1.VotedGui.VotedAmount.Text = "0"
MapVote.Vote2.VotedGui.VotedAmount.Text = "0"
MapVote.Vote3.VotedGui.VotedAmount.Text = "0"
Images.MapImage1.MapGui.MapImage.ImageTransparency = 1
Images.MapImage2.MapGui.MapImage.ImageTransparency = 1
Images.MapImage3.MapGui.MapImage.ImageTransparency = 1
Names.MapName1.MapNameGui.MapName.Text = ""
Names.MapName2.MapNameGui.MapName.Text = ""
Names.MapName3.MapNameGui.MapName.Text = ""
Images.MapImage1.MapGui.MapImage.Image = ""
Images.MapImage2.MapGui.MapImage.Image = ""
Images.MapImage3.MapGui.MapImage.Image = ""
print(mapName)
return mapName
end
Pads.VotePad1.Touched:Connect(function(touch)
onPadTouched(touch, MapVote.Vote1)
end)
Pads.VotePad2.Touched:Connect(function(touch)
onPadTouched(touch, MapVote.Vote2)
end)
Pads.VotePad3.Touched:Connect(function(touch)
onPadTouched(touch, MapVote.Vote3)
end)