What do you want to achieve? To have the “signaali” part change it’s brickcolor into Lime Green when all 3 of the Texts of the TextLabels are 9, 4 and 1 respectively.
What is the issue? The part doesn’t change it’s color and it seems like the condition doesn’t trigger as true.
What solutions have you tried so far? I tried troubleshooting it and tried other ways to do the same thing, but I keep running into this problem.
local arvo = script.Parent.kalikka1.SurfaceGui.TextLabel
local arvo2 = script.Parent.kalikka2.SurfaceGui.TextLabel
local arvo3 = script.Parent.kalikka3.SurfaceGui.TextLabel
script.Parent.kalikka1.ClickDetector.MouseClick:Connect(function()
local num = tonumber(arvo.Text)+1
if num == 10 then
num = 0
end
arvo.Text = num
end)
script.Parent.kalikka2.ClickDetector.MouseClick:Connect(function()
local num2 = tonumber(arvo2.Text)+1
if num2 == 10 then
num2 = 0
end
arvo2.Text = num2
end)
script.Parent.kalikka3.ClickDetector.MouseClick:Connect(function()
local num3 = tonumber(arvo3.Text)+1
if num3 == 10 then
num3 = 0
end
arvo3.Text = num3
end)
local basuri1 = tonumber(arvo.Text)
local basuri2 = tonumber(arvo2.Text)
local basuri3 = tonumber(arvo3.Text)
if basuri1 == 9 and basuri2 == 4 and basuri3 == 1 then
script.Parent.signaali.BrickColor = BrickColor.new("Lime green")
end
(Specifically the last 5 lines are the problem part)
It’s because when you are doing
local num = tonumber(arvo.Text)+1
if arvo.Text is 9 it gets turned to 10 then right after if the number is 10 you are reseting the number back to 0
the last five lines are ok
It’s due to how you setup your script, the condition that checks if all 3 TextLabels have the numbers you mentioned is checked once. If you have a button that you press to check the labels, put the code in its event.
Otherwise, if you want it to do something as soon as you pick the right number, put the check in the events that handle incrementing the numbered text.
And some additional advice would be using a function to help reduce repeated code
local arvo = script.Parent.kalikka1.SurfaceGui.TextLabel
local arvo2 = script.Parent.kalikka2.SurfaceGui.TextLabel
local arvo3 = script.Parent.kalikka3.SurfaceGui.TextLabel
script.Parent.kalikka1.ClickDetector.MouseClick:Connect(function()
local num = tonumber(arvo.Text)+1
if num == 10 then
num = 0
end
arvo.Text = num
end)
script.Parent.kalikka2.ClickDetector.MouseClick:Connect(function()
local num2 = tonumber(arvo2.Text)+1
if num2 == 10 then
num2 = 0
end
arvo2.Text = num2
end)
script.Parent.kalikka3.ClickDetector.MouseClick:Connect(function()
local num3 = tonumber(arvo3.Text)+1
if num3 == 10 then
num3 = 0
end
arvo3.Text = num3
end)
script.Parent.kalikka4.ClickDetector.MouseClick:Connect(function()
local basuri1 = tonumber(arvo.Text)
local basuri2 = tonumber(arvo2.Text)
local basuri3 = tonumber(arvo3.Text)
if basuri1 == 9 and basuri2 == 4 and basuri3 == 1 then
script.Parent.signaali.BrickColor = BrickColor.new("Lime green")
end
end)
Add a fourth button where the check is performed, as the previous post stated the check is performed when the script first executes and never again after that.