The target color doesn’t change to a different color after I click the button bc both of them match which is the point of the game. Everything works its just that it stays the same color. I suspect it could be something to do with the coroutine.
Code:
local CS = game:GetService("CollectionService")
local AvailableColors = {
"Red";
"Orange";
"Yellow";
"Green";
"Blue";
"Magenta";
};
local ColorValues = {
["Red"] = Color3.fromRGB(255, 58, 58);
["Orange"] = Color3.fromRGB(255, 87, 57);
["Yellow"] = Color3.fromRGB(255, 242, 56);
["Green"] = Color3.fromRGB(73, 255, 79);
["Blue"] = Color3.fromRGB(38, 85, 255);
["Magenta"] = Color3.fromRGB(170, 0, 170);
};
shared.CurrentScore = 0
local RS = game:GetService("ReplicatedStorage")
local Difficulties = require(RS.Difficulties)
local ColorCatchers = workspace.ColorCatchers
local AddCatch = RS.RemoteEvents.AddCatch
local SetNewScore = RS.RemoteEvents.SetNewScore
for _, ColorCatcher in pairs(CS:GetTagged("ColorCatcher")) do
coroutine.resume(coroutine.create(function()
local Difficulty = ColorCatcher.Difficulty.Value
local ColorPlates = ColorCatcher.ColorPlates
local ChosenTargetColor
local PlrResponse = false
local ParticipationZone = ColorCatcher.ParticipationZone
ParticipationZone.DifficultyUI.Display.Text = string.upper(Difficulty)
ParticipationZone.DifficultyUI.Display.TextColor3 = Difficulties[Difficulty].Color
ColorPlates.CyclingColorPlate.ColorSignal.ClickDetector.MouseClick:Connect(function()
if not PlrResponse then
PlrResponse = true
local CurrentColor = ColorPlates.CyclingColorPlate.ColorSignal.Color
if CurrentColor == ColorValues[ChosenTargetColor] then
AddCatch:FireServer()
shared.CurrentScore += Difficulties[Difficulty].ScoreGain
else
if shared.CurrentScore > 0 then
SetNewScore:FireServer(shared.CurrentScore)
else
print("Didn't request a score change as the current score is lower than the best score.")
end
end
PlrResponse = false
end
end)
local PrevTargetColor = nil
while true do
repeat
ChosenTargetColor = AvailableColors[math.random(1,#AvailableColors)]
task.wait()
until ChosenTargetColor ~= PrevTargetColor
ChosenTargetColor = AvailableColors[math.random(1,#AvailableColors)]
print(PrevTargetColor)
print(ChosenTargetColor)
ColorPlates.TargetColorPlate.ColorSignal.Color = ColorValues[ChosenTargetColor]
local ChosenCurrentColor
local PrevCurrentColor = nil
repeat
repeat
ChosenCurrentColor = AvailableColors[math.random(1,#AvailableColors)]
task.wait()
until ChosenCurrentColor ~= PrevCurrentColor
PrevCurrentColor = ChosenCurrentColor
ColorPlates.CyclingColorPlate.ColorSignal.Color = ColorValues[ChosenCurrentColor]
task.wait(Difficulties[Difficulty].Interval)
until PlrResponse -- until its true
PrevTargetColor = ChosenTargetColor
task.wait()
end
end))
end
I think the issue lies here somewhere:
while true do
repeat
ChosenTargetColor = AvailableColors[math.random(1,#AvailableColors)]
task.wait()
until ChosenTargetColor ~= PrevTargetColor
ChosenTargetColor = AvailableColors[math.random(1,#AvailableColors)]
print(PrevTargetColor)
print(ChosenTargetColor)
ColorPlates.TargetColorPlate.ColorSignal.Color = ColorValues[ChosenTargetColor]
local ChosenCurrentColor
local PrevCurrentColor = nil
repeat
repeat
ChosenCurrentColor = AvailableColors[math.random(1,#AvailableColors)]
task.wait()
until ChosenCurrentColor ~= PrevCurrentColor
PrevCurrentColor = ChosenCurrentColor
ColorPlates.CyclingColorPlate.ColorSignal.Color = ColorValues[ChosenCurrentColor]
task.wait(Difficulties[Difficulty].Interval)
until PlrResponse -- until its true
PrevTargetColor = ChosenTargetColor
task.wait()
end