I've tried everything to fix this, but nothing works. There is no output. This is how the objects in the script look like in Explorer:
Frame
-Minigame1 (TextButton, it's text is "Minigame1". It's BackgroundColor3 is 255,255,255.)
- -Problem Script (The script that I'm trying to fix.)
- -Voted (BoolValue, It's value is False.)
-Minigame2 (TextButton, it's text is "Minigame2". It's BackgroundColor3 is 255,255,255.)
- -Problem Script (The script that I'm trying to fix.)
- -Voted (BoolValue, It's value is False.)
-Minigame3 (TextButton, it's text is "Minigame3". It's BackgroundColor3 is 255,255,255.)
- -Problem Script (The script that I'm trying to fix.)
- -Voted (BoolValue, It's value is False.)
Workspace
-Minigame1Votes (IntValue, it's value is 0.)
-Minigame2Votes (IntValue, it's value is 0.)
-Minigame3Votes (IntValue, it's value is 0.)
This is the problem script in the Buttons:
chosen = script.Parent:WaitForChild("Voted") script.Parent.MouseButton1Click:connect(function() if chosen.Value == false and script.Parent.BackgroundColor3 ~= Color3.new(0,1,0) then chosen.Value = true script.Parent.BackgroundColor3 = Color3.new(0,1,0) game.Workspace["" ..script.Parent.Text.. "Votes"].Value = game.Workspace["" ..script.Parent.Text.. "Votes"].Value + 1 local lastvoted = nil for i,v in pairs(script.Parent.Parent:GetChildren()) do if v:IsA("TextButton") then if v.Voted.Value == true then v.BackgroundColor3 = Color3.new(1,1,1) v.Voted.Value = false lastvoted = v end end end if lastvoted then if game.Workspace["" ..lastvoted.Text.. "Votes"].Value > 0 then game.Workspace["" ..lastvoted.Text.. "Votes"].Value = game.Workspace["" ..lastvoted.Text.. "Votes"].Value - 1 end end end end)
The button does not change color, nor do the values in Workspace change.
After trying to figure out what was going on here, I decided to take what you had and make it more efficient and simple. It seems that you're doing a lot of over thinking.
First off, instead of making it so that there is a script for every option, you can make it more efficient by adding all the options to an array, like so:
local options = {script.Parent.Minigame1, script.Parent.Minigame2, script.Parent.Minigame3}
Now that you have all the options in one place, you can call one function to run all three buttons.
local options = {script.Parent.Minigame1, script.Parent.Minigame2, script.Parent.Minigame3} for _, option in ipairs (options) do option.MouseButton1Click:connect(function() -- code end) end
After all this is in place, you can really simplify the code.
local options = {script.Parent.Minigame1, script.Parent.Minigame2, script.Parent.Minigame3} local currentVote -- Variable to hold what the players current vote is for _, option in ipairs (options) do option.MouseButton1Click:connect(function() if not currentVote and not option.Voted.Value then -- If they have no current vote -- Add new vote option.Voted.Value = true game.Workspace[tostring(option) .. "Votes"].Value = game.Workspace[tostring(option) .. "Votes"].Value + 1 option.BackgroundColor3 = Color3.new(0, 1, 0) currentVote = option elseif currentVote and not option.Voted.Value then -- If they have a current vote -- Remove previous vote currentVote.Voted.Value = false game.Workspace[tostring(currentVote) .. "Votes"].Value = game.Workspace[tostring(currentVote) .. "Votes"].Value - 1 currentVote.BackgroundColor3 = Color3.new(1, 1, 1) -- Add new vote option.Voted.Value = true game.Workspace[tostring(option) .. "Votes"].Value = game.Workspace[tostring(option) .. "Votes"].Value + 1 option.BackgroundColor3 = Color3.new(0, 1, 0) currentVote = option end end) end
And there you have it, a more efficient and simpler function!