I have made a true or false system for a guessing game I am making, it works the first time, it gives you 1 correct or 1 wrong depending on which one you click. However, if you do it twice on the "true" button, it multiplies. If you do it on "false" button, it gives you many wrongs and more corrects. I do not understand what is happening?
function onButtonClicked()
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.TextTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.BackgroundTransparency = 1
--Table Of States
local States = {}
States[1] = "Alabama"
States[2] = "Alaska"
States[3] = "Arizona"
States[4] = "Arkansas"
States[5] = "California"
States[6] = "Colorado"
States[7] = "Connecticut"
States[8] = "Delaware"
States[9] = "Florida"
States[10] = "Georgia"
States[11] = "Hawaii"
States[12] = "Idaho"
States[13] = "Illinois"
States[14] = "Indiana"
States[15] = "Iowa"
States[16] = "Kansas"
States[17] = "Kentucky"
States[18] = "Louisiana"
States[19] = "Maine"
States[20] = "Maryland"
States[21] = "Massachusetts"
States[22] = "Michigan"
States[23] = "Minnesota"
States[24] = "Mississippi"
States[25] = "Missouri"
States[26] = "Montana"
States[27] = "Nebraska"
States[28] = "Nevada"
States[29] = "New Hampshire"
States[30] = "New Jersey"
States[31] = "New Mexico"
States[32] = "New York"
States[33] = "North Carolina"
States[34] = "North Dakota"
States[35] = "Ohio"
States[36] = "Oklahoma"
States[37] = "Oregon"
States[38] = "Pennsylvania"
States[39] = "Rhode Island"
States[40] = "South Carolina"
States[41] = "South Dakota"
States[42] = "Tennessee"
States[43] = "Texas"
States[44] = "Utah"
States[45] = "Vermont"
States[46] = "Virginia"
States[47] = "Washington"
States[48] = "West Virginia"
States[49] = "Wisconsin"
States[50] = "Wyoming"
--Alabama
if States[math.random(1,1)] == "Alabama" then
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.Visible = true
local trueOrFalse = math.random(1,2)
if trueOrFalse == 1 then
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.TextLabel.Text = "Is this state Alabama?"
print (trueOrFalse)
local function onTrueActivated()
game:GetService("Players").LocalPlayer.leaderstats.Correct.Value = game:GetService("Players").LocalPlayer.leaderstats.Correct.Value + 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.TextTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.BackgroundTransparency = 0
wait(3)
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.TextTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.BackgroundTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.BackgroundTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.TextTransparency = 0
end
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.True.Activated:Connect(onTrueActivated)
local function onFalseActivated()
game:GetService("Players").LocalPlayer.leaderstats.Wrong.Value = game:GetService("Players").LocalPlayer.leaderstats.Wrong.Value + 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.TextTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.BackgroundTransparency = 0
wait(3)
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.TextTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.BackgroundTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.BackgroundTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.TextTransparency = 0
end
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.False.Activated:Connect(onFalseActivated)
else
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.TextLabel.Text = "Is this state "..States[math.random(2,50)].."?"
print (trueOrFalse)
local function onFalseActivated()
game:GetService("Players").LocalPlayer.leaderstats.Correct.Value = game:GetService("Players").LocalPlayer.leaderstats.Correct.Value + 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.TextTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.BackgroundTransparency = 0
wait(3)
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.TextTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Correct.BackgroundTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.BackgroundTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.TextTransparency = 0
end
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.False.Activated:Connect(onFalseActivated)
local function onTrueActivated()
game:GetService("Players").LocalPlayer.leaderstats.Wrong.Value = game:GetService("Players").LocalPlayer.leaderstats.Wrong.Value + 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.TextTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.BackgroundTransparency = 0
wait(3)
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.TextTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.CorrectWrongGui.Wrong.BackgroundTransparency = 1
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.Visible = false
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.BackgroundTransparency = 0
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.TextTransparency = 0
end
game.Players.LocalPlayer.PlayerGui.StateGui.AlabamaGui.Frame.True.Activated:Connect(onTrueActivated)
end
end
end
game.Players.LocalPlayer.PlayerGui.StateGui.QuestionMe.TextButton.Activated:Connect(onButtonClicked)

3 comments
Have you tried putting print statements in to see what’s being printed when you do what? That’s a good strategy when it comes to figuring out what’s happening in your code. When your code is off, always try and see exactly what’s happening before asking others. It could be a mixture of problems. I think you can figure it out on your own though. Just try and see if it’s being called more than once.
Like print(“hello”) in the if statements and see what’s happening inside there. Print the values of the variables. It’ll show you more of what’s going on
I've decided to remove leaderstats and work on a different system.