Color game not working!

Idk why this local script doesnt work, this is some info: Everything in the game is put right in starterGui so please help me:

local colorFrame = script.Parent.ColorFrame
local colorButton = script.Parent.ColorButton
local alive = true
local clicked = false
local minimumTime = 150
local timeNumber = 500
local points = 0

task.wait(5)

while true do
	
	minimumTime = 150
	timeNumber = 500
	
	local alive = true
	local clicked = false
	
	while alive == true do
		colorFrame.BackgroundColor3 = Color3.new(1, 0.364706, 0.376471)

		local randomTime = math.random(minimumTime,timeNumber) / 100
		
		wait(randomTime)
		
		colorFrame.BackgroundColor3 = Color3.new(0.415686, 1, 0.482353)
		
		timeNumber -= math.floor(timeNumber / 100)
		minimumTime -= 2
		
		colorButton.MouseButton1Down:Connect(function()
			if colorFrame.BackgroundColor3 == Color3.new(0.415686, 1, 0.482353) then
				colorFrame.BackgroundColor3 = Color3.new(1, 0.364706, 0.376471)
				points += 1
				clicked = true
			elseif colorFrame.BackgroundColor3 == Color3.new(1, 0.364706, 0.376471) then
				alive = false
				clicked = true
			end
		end)
		
		wait(0.5)
		
		if clicked == false then
			alive = false
		end
		
		clicked = false
	end
	
	colorFrame.BackgroundColor3 = Color3.new(255, 255, 255)
	
	-- give player points
	
	print(points)
	
	points = 0
	
	wait(10)
end
1 Like
  1. Perhaps you should try to use :WaitForChild() method on the gui elements instead of using task.wait(5). There is a chance that the gui elements take longer than 5 seconds to get from the server.

  2. I see that you did colorFrame.BackgroundColor3 = Color3.new(255, 255, 255). The new() method in the Color3 take 3 floats each in the range of [0; 1]. If you wish to use RGB then you should use the fromRGB() method instead, which takes 3 integers in range of [0; 255]

Do you see any error messages?

What is not working? What do you expect to happen?

One thing I noted, you don’t need to connect the mouse button down event every time the loop runs as the function inside doesn’t change. You could place this at the start outside the loops.

it stop at the second click when I play