Background color won't change

Hello,
I have this extremely annoying problem, where the background color won’t change!
Script:

Enter.MouseButton1Click:Connect(function()
	if StartSum then
		if CodeHere.Text == tostring(StartSum1 + StartSum2) then
			Dots.Remaining1.BackgroundColor3 = Color3.fromRGB(0,255,0)
			StartSum = false
			Sum21 = math.random(10,40)
			Sum22 = math.random(7,30)
			Sum2 = true
			Solve.Text = Sum21..'+'..Sum22
		else
			Setup()
		end
	end
end)

I have a textlabel in my Dots folder which I want to change the background color of, to green. They’re currently red.

Layout:

fdfsdfsdfsdfs

I’ve added prints, so I know it’s getting to that part.
No errors, so what’s happening??

Upload a studio file with the gui

CodePanel.rbxm (10.0 KB)

1 Like

Please provide the full length of code so we can better understand the issue.

The mostly likely issue is

You will most likely want to set it with Color3.New.

in this discussion they talk about needing to devise it by 255 so if you get bigger numbers use this.

local Frame = script.Parent:WaitForChild('Frame')
local Enter = Frame:WaitForChild('Enter')
local TimeLeft = Frame:WaitForChild('TimeLeft')
local CodeHere = Frame:WaitForChild('CodeHere')
local Solve = Frame:WaitForChild('Solve')
local Dots = Frame:WaitForChild('Dots')

local StartSum1
local StartSum2


local StartSum = true
local Sum2 = false
local Sum3 = false
local Sum4 = false
local Sum5 = false
local Completed = false

local function Setup()
	local StartSum = true
	local Sum2 = false
	local Sum3 = false
	local Sum4 = false
	local Sum5 = false
	StartSum1 = math.random(5,30)
	StartSum2 = math.random(3,20)
	Solve.Text = StartSum1..'+'..StartSum2
	for _, Dot in pairs(Dots:GetChildren()) do
		Dot.BackgroundColor3 = Color3.fromRGB(204, 0, 0)
	end
end

Setup()



Enter.MouseButton1Click:Connect(function()
	if StartSum then
		if CodeHere.Text == tostring(StartSum1 + StartSum2) then
			Dots.Remaining1.BackgroundColor3 = Color3.new(0,1,0)
			print('running!')
			StartSum = false
			Sum21 = math.random(10,40)
			Sum22 = math.random(7,30)
			Sum2 = true
			Solve.Text = Sum21..'+'..Sum22
		else
			Setup()
		end
	end
	
	if Sum2 then
		if CodeHere.Text == Sum21 + Sum22 then
			Dots.Remaining2.BackgroundColor3 = Color3.fromRGB(0,255,0)
			Sum2 = false
			Sum31 = math.random(20,60)
			Sum32 = math.random(12,40)
			Sum3 = true
			Solve.Text = Sum31..'+'..Sum32
		else
			Setup()
		end
	end
	
	if Sum3 then
		if CodeHere.Text == Sum21 + Sum22 then
			Dots.Remaining2.BackgroundColor3 = Color3.fromRGB(0,255,0)
			Sum2 = false
			Sum31 = math.random(20,60)
			Sum32 = math.random(12,40)
			Sum3 = true
			Solve.Text = Sum31..'+'..Sum32
		else
			Setup()
		end
	end
end)


I’ve never had an issue with Color3.fromRGB(). The issue most likely lies in the conditional statement. Either returning false or nil.

Running… prints, so I know that the code is running where the background transparency is set.

Is Remaining2 a Frame or a Image?

Your Setup() function is changing it back every time

Only when StartSum is false. What could be happening is he is setting the BackgroundColor3 instead of ImageColor3 assuming it’s an image not a Frame or other Ui object.

I’m only calling it if the answer is wrong though, but it’s correct.

What is the class of Remaining1?

1 Like

TextLabel…

yeah, that’s happening after I added prints, but why?

CodePanel.rbxm (10.1 KB)

Script
local Frame = script.Parent:WaitForChild('Frame')
local Enter = Frame:WaitForChild('Enter')
local TimeLeft = Frame:WaitForChild('TimeLeft')
local CodeHere = Frame:WaitForChild('CodeHere')
local Solve = Frame:WaitForChild('Solve')
local Dots = Frame:WaitForChild('Dots')


local CurrentLevel = 1
local CurrentQuestion = {0, 0, 0}
local EnterButtonEnabled = true
local Levels = {
	{
		VarOne={5, 30},
		VarTwo={3, 20}
	},
	{
		VarOne={10, 40},
		VarTwo={7, 30}
	},
	{
		VarOne={20, 60},
		VarTwo={12, 40}
	},
}


CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])


function NextLevel()
	if CurrentLevel == #Levels then
		EnterButtonEnabled = false
		Solve.Text = "You Win!"
		wait(1.25)
		CurrentLevel = 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(204,0,0)
		end
		EnterButtonEnabled = true
	else
		CurrentLevel += 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end



Enter.MouseButton1Click:Connect(function()
	if EnterButtonEnabled == false then return end
	if CodeHere.Text == tostring(CurrentQuestion[3]) then
		for i,v in pairs(Dots:GetChildren()) do
			if v.Name == ("Remaining"..CurrentLevel) then
				v.BackgroundColor3 = Color3.fromRGB(0,255,0)
			end
		end
		NextLevel()
	else
		CurrentLevel = 1
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(255,0,0)
		end
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end)
1 Like

I tried adding an extra 2 levels on, to make it 5, but I’m getting the error:

Script:

local Frame = script.Parent:WaitForChild('Frame')
local Enter = Frame:WaitForChild('Enter')
local TimeLeft = Frame:WaitForChild('TimeLeft')
local CodeHere = Frame:WaitForChild('CodeHere')
local Solve = Frame:WaitForChild('Solve')
local Dots = Frame:WaitForChild('Dots')


local CurrentLevel = 1
local CurrentQuestion = {0, 0, 0}
local EnterButtonEnabled = true
local Levels = {
	{
		VarOne={5, 30},
		VarTwo={3, 20}
	},
	{
		VarOne={10, 40},
		VarTwo={7, 30}
	},
	{
		VarOne={20, 60},
		VarTwo={12, 40}
	},
	{
		VarOne = {40,80},
		VarTwo = {30,70}
	},
	{
		VarOne = {50,100},
		VarTwo = {40,90}
	},
}


CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
CurrentQuestion[4] = math.random(Levels[CurrentLevel].VarOne[4], Levels[CurrentLevel].VarOne[4])
CurrentQuestion[5] = math.random(Levels[CurrentLevel].VarTwo[5], Levels[CurrentLevel].VarTwo[5])
Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])


function NextLevel()
	if CurrentLevel == #Levels then
		EnterButtonEnabled = false
		Solve.Text = "You Win!"
		wait(1.25)
		CurrentLevel = 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		CurrentQuestion[4] = math.random(Levels[CurrentLevel].VarOne[4], Levels[CurrentLevel].VarOne[4])
		CurrentQuestion[5] = math.random(Levels[CurrentLevel].VarTwo[5], Levels[CurrentLevel].VarTwo[5])
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(204,0,0)
		end
		EnterButtonEnabled = true
	else
		CurrentLevel += 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		CurrentQuestion[4] = math.random(Levels[CurrentLevel].VarOne[4], Levels[CurrentLevel].VarOne[4])
		CurrentQuestion[5] = math.random(Levels[CurrentLevel].VarTwo[5], Levels[CurrentLevel].VarTwo[5])
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end



Enter.MouseButton1Click:Connect(function()
	if EnterButtonEnabled == false then return end
	if CodeHere.Text == tostring(CurrentQuestion[3]) then
		for i,v in pairs(Dots:GetChildren()) do
			if v.Name == ("Remaining"..CurrentLevel) then
				v.BackgroundColor3 = Color3.fromRGB(0,255,0)
			end
		end
		NextLevel()
	else
		CurrentLevel = 1
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(255,0,0)
		end
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end)

You do not need to change anything except for the table, the other stuff you added is what is causing the error.

Example
local Frame = script.Parent:WaitForChild('Frame')
local Enter = Frame:WaitForChild('Enter')
local TimeLeft = Frame:WaitForChild('TimeLeft')
local CodeHere = Frame:WaitForChild('CodeHere')
local Solve = Frame:WaitForChild('Solve')
local Dots = Frame:WaitForChild('Dots')


local CurrentLevel = 1
local CurrentQuestion = {0, 0, 0}
local EnterButtonEnabled = true
local Levels = {
	{
		VarOne={5, 30},
		VarTwo={3, 20}
	},
	{
		VarOne={10, 40},
		VarTwo={7, 30}
	},
	{
		VarOne={20, 60},
		VarTwo={12, 40}
	},
	{
		VarOne = {40,80},
		VarTwo = {30,70}
	},
	{
		VarOne = {50,100},
		VarTwo = {40,90}
	},
}


CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])


function NextLevel()
	if CurrentLevel == #Levels then
		EnterButtonEnabled = false
		Solve.Text = "You Win!"
		wait(1.25)
		CurrentLevel = 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(204,0,0)
		end
		EnterButtonEnabled = true
	else
		CurrentLevel += 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end



Enter.MouseButton1Click:Connect(function()
	if EnterButtonEnabled == false then return end
	if CodeHere.Text == tostring(CurrentQuestion[3]) then
		for i,v in pairs(Dots:GetChildren()) do
			if v.Name == ("Remaining"..CurrentLevel) then
				v.BackgroundColor3 = Color3.fromRGB(0,255,0)
			end
		end
		NextLevel()
	else
		CurrentLevel = 1
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(255,0,0)
		end
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end)
1 Like

Added a timer incase you have problems trying to get it working with the new levels “system”

Timer
local Frame = script.Parent:WaitForChild('Frame')
local Enter = Frame:WaitForChild('Enter')
local TimeLeft = Frame:WaitForChild('TimeLeft')
local CodeHere = Frame:WaitForChild('CodeHere')
local Solve = Frame:WaitForChild('Solve')
local Dots = Frame:WaitForChild('Dots')


local CurrentLevel = 1
local CurrentQuestion = {0, 0, 0}
local EnterButtonEnabled = true


local Levels = {
	{
		VarOne={5, 30},
		VarTwo={3, 20},
		Time=15
	},
	{
		VarOne={10, 40},
		VarTwo={7, 30},
		Time=20
	},
	{
		VarOne={20, 60},
		VarTwo={12, 40},
		Time=30
	},
	{
		VarOne = {40,80},
		VarTwo = {30,70},
		Time=35
	},
	{
		VarOne = {50,100},
		VarTwo = {40,90},
		Time=40
	},
}


local LastTimeAnswered = tick()
spawn(function()
	while true do
		if CurrentLevel > 1 then
			local TimePassed = tick() - LastTimeAnswered
			if TimePassed >= Levels[CurrentLevel].Time then
				EnterButtonEnabled = false
				Solve.Text = "The time ran out!"
				wait(1.25)
				CurrentLevel = 1
				CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
				CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
				CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
				Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
				for i,v in pairs(Dots:GetChildren()) do
					v.BackgroundColor3 = Color3.fromRGB(204,0,0)
				end
				EnterButtonEnabled = true
			else
				TimeLeft.Text = tostring(Levels[CurrentLevel].Time - math.ceil(TimePassed))
			end
		end
		wait(0.35)
	end
end)


CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
TimeLeft.Text = tostring(Levels[CurrentLevel].Time)
Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])


function NextLevel()
	if CurrentLevel == #Levels then
		EnterButtonEnabled = false
		Solve.Text = "You Win!"
		wait(1.25)
		CurrentLevel = 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		TimeLeft.Text = tostring(Levels[CurrentLevel].Time)
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(204,0,0)
		end
		EnterButtonEnabled = true
	else
		CurrentLevel += 1
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		TimeLeft.Text = tostring(Levels[CurrentLevel].Time)
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end



Enter.MouseButton1Click:Connect(function()
	if EnterButtonEnabled == false then return end
	if CodeHere.Text == tostring(CurrentQuestion[3]) then
		for i,v in pairs(Dots:GetChildren()) do
			if v.Name == ("Remaining"..CurrentLevel) then
				v.BackgroundColor3 = Color3.fromRGB(0,255,0)
			end
		end
		LastTimeAnswered = tick()
		NextLevel()
	else
		CurrentLevel = 1
		for i,v in pairs(Dots:GetChildren()) do
			v.BackgroundColor3 = Color3.fromRGB(204,0,0)
		end
		CurrentQuestion[1] = math.random(Levels[CurrentLevel].VarOne[1], Levels[CurrentLevel].VarOne[2])
		CurrentQuestion[2] = math.random(Levels[CurrentLevel].VarTwo[1], Levels[CurrentLevel].VarTwo[2])
		CurrentQuestion[3] = CurrentQuestion[1] + CurrentQuestion[2]
		TimeLeft.Text = tostring(Levels[CurrentLevel].Time)
		Solve.Text = tostring(CurrentQuestion[1]).." + "..tostring(CurrentQuestion[2])
	end
end)
1 Like