Game starts but buttons not functional [RESOLVED]

Code:

local RS = game:GetService("ReplicatedStorage")

local ToggleGameUI = RS:WaitForChild("RemoteEvents"):WaitForChild("ToggleGameUI")

local InstructionsDisplay = script.Parent:WaitForChild("Instructions")

local ScoreDisplay = script.Parent:WaitForChild("ScoreDisplay")

local TimerDisplay = script.Parent:WaitForChild("TimerDisplay")

local InZone = false

local GameStarted = false

ToggleGameUI.OnClientEvent:Connect(function(Toggle)
	
	if Toggle == true then
		
		InZone = true
		
		InstructionsDisplay:TweenPosition(UDim2.new(0.371, 0,0.883, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.3)
		
	else
		
		if GameStarted == true then
			
			GameStarted = false
			
		end
		
		InZone = false
		
		InstructionsDisplay:TweenPosition(UDim2.new(0.371, 0,1, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.3)
		
	end
	
end)

local plr = game.Players.LocalPlayer

local Mouse = plr:GetMouse()

local GameModel = workspace:WaitForChild("Game")

Mouse.TargetFilter = GameModel:WaitForChild("GameDetectorArea")

local PointerTarget = nil

local UIS = game:GetService("UserInputService")

local Config = {
	Tiers = {
		[1] = {
			Odds = 90;
			ScoreVal = 25;
		};
		[2] = {
			Odds = 75;
			ScoreVal = 50;
		};
		[3] = {
			Odds = 60;
			ScoreVal = 75;
		};
		[4] = {
			Odds = 50;
			ScoreVal = 100;
		};
	};
	ButtonColors = {
		Neutral = Color3.fromRGB(85, 84, 86);
		StarNeutral = Color3.fromRGB(170, 0, 170);
		Gained = Color3.fromRGB(71, 244, 111);
		Lost = Color3.fromRGB(206, 72, 72);
	};
}

local RoundDuration = 120 -- 2 mins in seconds

local NewTopScore = RS:WaitForChild("RemoteEvents"):WaitForChild("NewTopScore")

local CS = game:GetService("CollectionService")

for _, TierOddsDisplay in pairs(CS:GetTagged("TierOddsDisplay")) do
	
	TierOddsDisplay.Text = Config.Tiers[TierOddsDisplay.Tier.Value].Odds .. "%"
	
end

local Buttons = GameModel:WaitForChild("Buttons")

local JackpotButton = Buttons:WaitForChild("JackpotButton")

local ToggleGameButton = Buttons:WaitForChild("ToggleGameButton")

local function ResetButtons()
	
	for _, Button in pairs(CS:GetTagged("GameButton")) do
		
		if Button ~= ToggleGameButton then
			
			if Button.Clicked.Value == true then

				Button.Clicked.Value = false

				if Button ~= JackpotButton then

					Button.Color = Config.ButtonColors.Neutral

				else

					Button.Color = Config.ButtonColors.StarNeutral

				end

			end
			
		end
		
	end
	
end

local function OutlineButtonOnHover()

	while true do
		
		for _, Button in pairs(CS:GetTagged("GameButton")) do

			if Button:FindFirstChildWhichIsA("Highlight") then

				Button:FindFirstChildWhichIsA("Highlight"):Destroy()

			end

		end

		for _, Button in pairs(CS:GetTagged("GameButton")) do

			if Button == PointerTarget then

				if Button ~= ToggleGameButton then

					if GameStarted == true then

						local ClonedHighlight = Instance.new("Highlight"):Clone()
						ClonedHighlight.Parent = Button

						ClonedHighlight.FillTransparency = 1

						ClonedHighlight.OutlineColor = Color3.fromRGB(171, 255, 245)

					end

				else
					
					if InZone == true then
						
						local ClonedHighlight = Instance.new("Highlight"):Clone()
						ClonedHighlight.Parent = Button

						ClonedHighlight.FillTransparency = 1

						ClonedHighlight.OutlineColor = Color3.fromRGB(171, 255, 245)
						
					end

				end

			end

		end

		task.wait()

	end

end

spawn(OutlineButtonOnHover)

local TotalScore = 0

local UpdatePlayerRoundData = RS:WaitForChild("RemoteEvents"):WaitForChild("UpdatePlayerRoundData")

local Duration = 0

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	
	if not gameProcessedEvent then
		
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			
			if PointerTarget ~= nil then
				
				if PointerTarget == ToggleGameButton then
					
					if InZone == true then
						
						if GameStarted == false then

							GameStarted = true

							ResetButtons()

							InstructionsDisplay:TweenPosition(UDim2.new(0.371, 0,1, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.3)

							task.wait(0.3)

							ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

							for secs = 120,0,-1 do

								if GameStarted == true then

									local mins = math.floor(secs / 60)

									local secs_remaining = secs % 60

									TimerDisplay.Text = string.format("%d:%02d", mins, secs_remaining)

									Duration = secs

								else

									break

								end

								task.wait(1)

							end

							GameStarted = false

							TimerDisplay.Text = ""

							ScoreDisplay.Text = ""

							UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

							if TotalScore > plr.leaderstats:FindFirstChild("Top Score").Value then

								NewTopScore:FireServer(TotalScore)

							end

							TotalScore = 0

						else

							GameStarted = false

							ScoreDisplay.Text = ""

							UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

							if TotalScore > plr.leaderstats:FindFirstChild("Top Score").Value then

								NewTopScore:FireServer(TotalScore)

							end

							TotalScore = 0

						end

					else

						if GameStarted == true then

							if PointerTarget.Clicked.Value == false then

								PointerTarget.Clicked.Value = true

								local RNG = math.random(1,100)

								if PointerTarget == JackpotButton then

									local OddsForJackpot = math.floor(((Config.Tiers[1].Odds / 4) + (Config.Tiers[2].Odds / 4) + (Config.Tiers[3].Odds / 4) + (Config.Tiers[4].Odds / 4)) / 4)

									print("Odds of getting a perfect score: " .. OddsForJackpot .. "%")

									if RNG <= OddsForJackpot then -- 11 or 12

										PointerTarget.Color = Config.ButtonColors.Gained

										TotalScore += 500

										ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

										local ButtonsClicked = 0 -- atleast 16

										for _, Button in pairs(CS:GetTagged("GameButton")) do

											if Button ~= JackpotButton and Button ~= ToggleGameButton then

												if Button.Clicked.Value == true then

													ButtonsClicked += 1

												end

											end

										end

										if ButtonsClicked == 16 then

											GameStarted = false

											TimerDisplay.Text = ""

											ScoreDisplay.Text = ""

											UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

											if TotalScore > plr.leaderstats:FindFirstChild("Top Score").Value then

												NewTopScore:FireServer(TotalScore)

											end

											TotalScore = 0

											UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

										end

									else

										PointerTarget.Color = Config.ButtonColors.Lost

									end

								else
									
									if RNG <= Config.Tiers[PointerTarget.Tier.Value].Odds then

										PointerTarget.Color = Config.ButtonColors.Gained

										TotalScore += Config.Tiers[PointerTarget.Tier.Value].ScoreVal

										ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

										local ButtonsClicked = 0 -- atleast 16

										for _, Button in pairs(CS:GetTagged("GameButton")) do

											if Button ~= JackpotButton and Button ~= ToggleGameButton then

												if Button.Clicked.Value == true then

													ButtonsClicked += 1

												end

											end

										end

										if ButtonsClicked == 16 then

											GameStarted = false

										end

									else

										PointerTarget.Color = Config.ButtonColors.Lost

										if PointerTarget.Tier.Value == 4 then

											TotalScore -= Config.Tiers[PointerTarget.Tier.Value].ScoreVal / 2

										else

											TotalScore -= Config.Tiers[PointerTarget.Tier.Value].ScoreVal

										end

										ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

										local ButtonsClicked = 0 -- atleast 16

										for _, Button in pairs(CS:GetTagged("GameButton")) do

											if Button ~= JackpotButton and Button ~= ToggleGameButton then

												if Button.Clicked.Value == true then

													ButtonsClicked += 1

												end

											end

										end

										if ButtonsClicked == 16 then

											GameStarted = false

										end

									end

								end

							end

						end
						
					end

				end
				
			end
			
		end
		
	end
	
end)

local LastRoundDisplay = GameModel:WaitForChild("RightBackBoard"):WaitForChild("LastRoundDisplay")

local LastRoundDate = LastRoundDisplay:WaitForChild("UI"):WaitForChild("Holder"):WaitForChild("LastRoundDate")

local LastRoundDuration = LastRoundDisplay:WaitForChild("UI"):WaitForChild("Holder"):WaitForChild("LastRoundDuration")

local LastRoundScore = LastRoundDisplay:WaitForChild("UI"):WaitForChild("Holder"):WaitForChild("LastRoundScore")

local PlrLastRoundInfoFolder = plr:WaitForChild("LastRoundInfo")

local PlrLastRoundDate = PlrLastRoundInfoFolder:WaitForChild("LastRoundDate")

local PlrLastRoundDuration = PlrLastRoundInfoFolder:WaitForChild("LastRoundDuration")

local PlrLastRoundScore = PlrLastRoundInfoFolder:WaitForChild("LastRoundScore")

local function SetLastRoundInfo()
	
	while true do
		
		-- Convert epoch time to a date table
		local dateTable = os.date("*t", PlrLastRoundDate.Value)

		-- Define the month names for formatting
		local monthNames = {
			"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
		}

		-- Format the date string with a shortened day name
		local formattedDate = string.format("%s, %s %d, %d %02d:%02d %s",
			os.date("%a", PlrLastRoundDate.Value), -- Shortened day name
			monthNames[dateTable.month], -- Month abbreviation
			dateTable.day, -- Day of the month
			dateTable.year, -- Year
			dateTable.hour - 12, -- Hour (24-hour format)
			dateTable.min, -- Minutes
			dateTable.hour < 12 and "AM" or "PM" -- AM or PM
		)
		
		if PlrLastRoundDate.Value ~= 0 then
			
			LastRoundDate.Text = "DATE: " .. formattedDate

			local TotalSecs = 120 - PlrLastRoundDuration.Value

			local mins = math.floor(TotalSecs / 60)

			local secs = TotalSecs % 60

			LastRoundDuration.Text = "DURATION: " .. string.format("%d:%02d", mins, secs)

			LastRoundScore.Text = "SCORE: " .. [[<font color="rgb(252, 255, 98)">]] .. PlrLastRoundScore.Value .. [[</font>]]
			
		else
			
			LastRoundDate.Text = "DATE: N/A"

			LastRoundDuration.Text = "DURATION: N/A"

			LastRoundScore.Text = "SCORE: N/A"
			
		end
		
		task.wait(1)
		
	end
	
end

spawn(SetLastRoundInfo)

while true do
	
	if Mouse.Target then
		
		if Mouse.Target:IsDescendantOf(Buttons) then
			
			PointerTarget = Mouse.Target
			
			if InZone == true then
				
				Mouse.Icon = "http://www.roblox.com/asset/?id=15441891191"
				
			else
				
				Mouse.Icon = ""
				
			end
			
		else
			
			PointerTarget = nil
			
			Mouse.Icon = ""
			
		end
		
	end
	
	task.wait()
	
end

-- Mouse.Icon = "http://www.roblox.com/asset?id=0"

Im sorry ik the code is like 500 lines

The issue is that it wont subtract or add score when the button is pressed nor will it change the color

I think the issue starts at UIS.InputBegan:Connect(function(input, gameProcessedEvent)

Can you maybe explain what the problem is as I don’t think anyone will read all of your code and try to see if there is anything wrong

The issue is that it wont subtract or add score when the button is pressed nor will it change the color

Maybe send the only things relevant as I don’t think knowing the Roundlength will help us solve the problem

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	
	if not gameProcessedEvent then
		
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			
			if PointerTarget ~= nil then
				
				if PointerTarget == ToggleGameButton then
					
					if InZone == true then
						
						if GameStarted == false then

							GameStarted = true

							ResetButtons()

							InstructionsDisplay:TweenPosition(UDim2.new(0.371, 0,1, 0),Enum.EasingDirection.InOut,Enum.EasingStyle.Sine,0.3)

							task.wait(0.3)

							ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

							for secs = 120,0,-1 do

								if GameStarted == true then

									local mins = math.floor(secs / 60)

									local secs_remaining = secs % 60

									TimerDisplay.Text = string.format("%d:%02d", mins, secs_remaining)

									Duration = secs

								else

									break

								end

								task.wait(1)

							end

							GameStarted = false

							TimerDisplay.Text = ""

							ScoreDisplay.Text = ""

							UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

							if TotalScore > plr.leaderstats:FindFirstChild("Top Score").Value then

								NewTopScore:FireServer(TotalScore)

							end

							TotalScore = 0

						else

							GameStarted = false

							ScoreDisplay.Text = ""

							UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

							if TotalScore > plr.leaderstats:FindFirstChild("Top Score").Value then

								NewTopScore:FireServer(TotalScore)

							end

							TotalScore = 0

						end

					else

						if GameStarted == true then

							if PointerTarget.Clicked.Value == false then

								PointerTarget.Clicked.Value = true

								local RNG = math.random(1,100)

								if PointerTarget == JackpotButton then

									local OddsForJackpot = math.floor(((Config.Tiers[1].Odds / 4) + (Config.Tiers[2].Odds / 4) + (Config.Tiers[3].Odds / 4) + (Config.Tiers[4].Odds / 4)) / 4)

									print("Odds of getting a perfect score: " .. OddsForJackpot .. "%")

									if RNG <= OddsForJackpot then -- 11 or 12

										PointerTarget.Color = Config.ButtonColors.Gained

										TotalScore += 500

										ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

										local ButtonsClicked = 0 -- atleast 16

										for _, Button in pairs(CS:GetTagged("GameButton")) do

											if Button ~= JackpotButton and Button ~= ToggleGameButton then

												if Button.Clicked.Value == true then

													ButtonsClicked += 1

												end

											end

										end

										if ButtonsClicked == 16 then

											GameStarted = false

											TimerDisplay.Text = ""

											ScoreDisplay.Text = ""

											UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

											if TotalScore > plr.leaderstats:FindFirstChild("Top Score").Value then

												NewTopScore:FireServer(TotalScore)

											end

											TotalScore = 0

											UpdatePlayerRoundData:FireServer(os.time(), Duration, TotalScore)

										end

									else

										PointerTarget.Color = Config.ButtonColors.Lost

									end

								else
									
									if RNG <= Config.Tiers[PointerTarget.Tier.Value].Odds then

										PointerTarget.Color = Config.ButtonColors.Gained

										TotalScore += Config.Tiers[PointerTarget.Tier.Value].ScoreVal

										ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

										local ButtonsClicked = 0 -- atleast 16

										for _, Button in pairs(CS:GetTagged("GameButton")) do

											if Button ~= JackpotButton and Button ~= ToggleGameButton then

												if Button.Clicked.Value == true then

													ButtonsClicked += 1

												end

											end

										end

										if ButtonsClicked == 16 then

											GameStarted = false

										end

									else

										PointerTarget.Color = Config.ButtonColors.Lost

										if PointerTarget.Tier.Value == 4 then

											TotalScore -= Config.Tiers[PointerTarget.Tier.Value].ScoreVal / 2

										else

											TotalScore -= Config.Tiers[PointerTarget.Tier.Value].ScoreVal

										end

										ScoreDisplay.Text = "Score: " .. [[<font color="rgb(252, 255, 98)">]] .. TotalScore .. [[</font>]]

										local ButtonsClicked = 0 -- atleast 16

										for _, Button in pairs(CS:GetTagged("GameButton")) do

											if Button ~= JackpotButton and Button ~= ToggleGameButton then

												if Button.Clicked.Value == true then

													ButtonsClicked += 1

												end

											end

										end

										if ButtonsClicked == 16 then

											GameStarted = false

										end

									end

								end

							end

						end
						
					end

				end
				
			end
			
		end
		
	end
	
end)