I am making a pattern type puzzle for a game I’m working on. The way it works is there are four symbols. The pattern will quickly flash the order of these symbols. The player must then click on each of them in that order, creating the same pattern. This will of course reward the player (the reward is irrelevant.) If the player messes something up, a “trigger” function will be called, (what the trigger function does is also irrelevant.) All of this works fine the first time the pattern is activated. But the second time it get’s activated, it calls the “trigger” function when it shouldn’t. Same goes for every time the player attempts to complete the puzzle afterwards. This is of course a major issue, since the player is being wrongfully penalized. Any help would be much appreciated!
local stage = 1
local debounce = false
local tweenservice = game:GetService("TweenService")
local circle = script.Parent.Circle
local button1 = script.Parent.One.Button1
local button2 = script.Parent.Two.Button2
local button3 = script.Parent.Three.Button3
local button4 = script.Parent.Four.Button4
local pattern1 = {button1,button2,button3, button4}
local pattern2 = {button3,button1,button4, button2}
local pattern3 = {button4,button3,button1, button2}
local pattern4 = {button2,button4,button3, button1}
local patternsTable = {pattern1, pattern2, pattern3, pattern4}
script.Parent.Trigger.Touched:Connect(function()
if debounce == false then
debounce = true
--Activate buttons
wait(0.5)
circle.Transparency = 0
wait(0.5)
circle.Transparency = 1
button3.Transparency = 0
wait(0.5)
circle.Transparency = 0
wait(0.5)
circle.Transparency = 1
button2.Transparency = 0
wait(0.5)
circle.Transparency = 0
wait(0.5)
circle.Transparency = 1
button1.Transparency = 0
wait(0.5)
circle.Transparency = 0
wait(0.5)
circle.Transparency = 1
button4.Transparency = 0
wait(0.5)
circle.Transparency = 1
local selectedPattern = patternsTable[math.random(1, #patternsTable)]
selectedPattern[1].BrickColor = BrickColor.new("Medium blue")
wait(0.5)
selectedPattern[1].BrickColor = BrickColor.new("202, 203, 209")
selectedPattern[2].BrickColor = BrickColor.new("Medium blue")
wait(0.5)
selectedPattern[2].BrickColor = BrickColor.new("202, 203, 209")
selectedPattern[3].BrickColor = BrickColor.new("Medium blue")
wait(0.5)
selectedPattern[3].BrickColor = BrickColor.new("202, 203, 209")
selectedPattern[4].BrickColor = BrickColor.new("Medium blue")
wait(0.5)
selectedPattern[4].BrickColor = BrickColor.new("202, 203, 209")
wait(0.5)
selectedPattern[1].Parent.Button.ClickDetector.MaxActivationDistance = 15
selectedPattern[2].Parent.Button.ClickDetector.MaxActivationDistance = 15
selectedPattern[3].Parent.Button.ClickDetector.MaxActivationDistance = 15
selectedPattern[4].Parent.Button.ClickDetector.MaxActivationDistance = 15
selectedPattern[1].Parent.Button.ClickDetector.MouseClick:Connect(function()
if stage == 1 then
print("Stage one complete")
stage = 2
selectedPattern[1].BrickColor = BrickColor.new("Sand green")
selectedPattern[1].Parent.Button.ClickDetector.MaxActivationDistance = 0
else
trigger()
end
end)
selectedPattern[2].Parent.Button.ClickDetector.MouseClick:Connect(function()
if stage == 2 then
print("Stage two complete")
stage = 3
selectedPattern[2].BrickColor = BrickColor.new("Sand green")
selectedPattern[2].Parent.Button.ClickDetector.MaxActivationDistance = 0
else
trigger()
end
end)
selectedPattern[3].Parent.Button.ClickDetector.MouseClick:Connect(function()
if stage == 3 then
print("Stage three complete")
stage = 4
selectedPattern[3].BrickColor = BrickColor.new("Sand green")
selectedPattern[3].Parent.Button.ClickDetector.MaxActivationDistance = 0
else
trigger()
end
end)
selectedPattern[4].Parent.Button.ClickDetector.MouseClick:Connect(function()
if stage == 4 then
print("Stage four complete")
print("You got the pattern correct!")
stage = 1
selectedPattern[4].BrickColor = BrickColor.new("Sand green")
selectedPattern[4].Parent.Button.ClickDetector.MaxActivationDistance = 0
wait(0.5)
selectedPattern[1].BrickColor = BrickColor.new("Institutional white")
selectedPattern[2].BrickColor = BrickColor.new("Institutional white")
selectedPattern[3].BrickColor = BrickColor.new("Institutional white")
selectedPattern[4].BrickColor = BrickColor.new("Institutional white")
circle.BrickColor = BrickColor.new("Institutional white")
wait(0.3)
selectedPattern[1].BrickColor = BrickColor.new("Sand green")
selectedPattern[2].BrickColor = BrickColor.new("Sand green")
selectedPattern[3].BrickColor = BrickColor.new("Sand green")
selectedPattern[4].BrickColor = BrickColor.new("Sand green")
circle.BrickColor = BrickColor.new("Sand green")
wait(0.3)
selectedPattern[1].BrickColor = BrickColor.new("Institutional white")
selectedPattern[2].BrickColor = BrickColor.new("Institutional white")
selectedPattern[3].BrickColor = BrickColor.new("Institutional white")
selectedPattern[4].BrickColor = BrickColor.new("Institutional white")
circle.BrickColor = BrickColor.new("Institutional white")
wait(0.3)
selectedPattern[1].BrickColor = BrickColor.new("Sand green")
selectedPattern[2].BrickColor = BrickColor.new("Sand green")
selectedPattern[3].BrickColor = BrickColor.new("Sand green")
selectedPattern[4].BrickColor = BrickColor.new("Sand green")
circle.BrickColor = BrickColor.new("Sand green")
wait(0.3)
selectedPattern[1].BrickColor = BrickColor.new("Institutional white")
selectedPattern[2].BrickColor = BrickColor.new("Institutional white")
selectedPattern[3].BrickColor = BrickColor.new("Institutional white")
selectedPattern[4].BrickColor = BrickColor.new("Institutional white")
circle.BrickColor = BrickColor.new("Institutional white")
wait(0.3)
selectedPattern[1].BrickColor = BrickColor.new("Sand green")
selectedPattern[2].BrickColor = BrickColor.new("Sand green")
selectedPattern[3].BrickColor = BrickColor.new("Sand green")
selectedPattern[4].BrickColor = BrickColor.new("Sand green")
circle.BrickColor = BrickColor.new("Sand green")
wait(0.3)
selectedPattern[1].BrickColor = BrickColor.new("Institutional white")
selectedPattern[2].BrickColor = BrickColor.new("Institutional white")
selectedPattern[3].BrickColor = BrickColor.new("Institutional white")
selectedPattern[4].BrickColor = BrickColor.new("Institutional white")
circle.BrickColor = BrickColor.new("Institutional white")
wait(0.3)
selectedPattern[1].BrickColor = BrickColor.new("Sand green")
selectedPattern[2].BrickColor = BrickColor.new("Sand green")
selectedPattern[3].BrickColor = BrickColor.new("Sand green")
selectedPattern[4].BrickColor = BrickColor.new("Sand green")
circle.BrickColor = BrickColor.new("Sand green")
wait(0.5)
circle.Transparency = 1
wait(0.5)
circle.Transparency = 0
button3.Transparency = 1
wait(0.5)
circle.Transparency = 1
wait(0.5)
circle.Transparency = 0
button2.Transparency = 1
wait(0.5)
circle.Transparency = 1
wait(0.5)
circle.Transparency = 0
button1.Transparency = 1
wait(0.5)
circle.Transparency = 1
wait(0.5)
circle.Transparency = 0
button4.Transparency = 1
wait(0.5)
circle.Transparency = 1
wait(1)
tweenservice:Create(script.Parent.Door, TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = script.Parent.Door.Position + Vector3.new(0,7,0)}):Play()
tweenservice:Create(script.Parent.Screen, TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = script.Parent.Screen.Position + Vector3.new(0,7,0)}):Play()
wait(10)
tweenservice:Create(script.Parent.Door, TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = script.Parent.Door.Position + Vector3.new(0,-7,0)}):Play()
tweenservice:Create(script.Parent.Screen, TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Position = script.Parent.Screen.Position + Vector3.new(0,-7,0)}):Play()
wait(6)
selectedPattern[1].BrickColor = BrickColor.new("Institutional white")
selectedPattern[2].BrickColor = BrickColor.new("Institutional white")
selectedPattern[3].BrickColor = BrickColor.new("Institutional white")
selectedPattern[4].BrickColor = BrickColor.new("Institutional white")
circle.BrickColor = BrickColor.new("Institutional white")
stage = 1
debounce = false
print("End of script")
else
trigger()
end
end)
end
end)
function trigger()
print("Triggered (You got the pattern incorrect)")
end
Attempt Num. 1 Output:
23:34:55.321 Stage one complete - Server - Script:204
23:34:56.037 Stage two complete - Server - Script:215
23:34:56.654 Stage three complete - Server - Script:226
23:34:57.237 Stage four complete - Server - Script:237
23:34:57.237 You got the pattern correct! - Server - Script:238
Attempt Num. 2 Output:
Stage one complete - Server - Script:204
23:36:03.551 Stage two complete - Server - Script:215
23:36:04.317 Triggered (You got the pattern incorrect) - Server - Script:349
23:36:04.318 Stage three complete - Server - Script:226
23:36:04.884 Triggered (You got the pattern incorrect) (x2) - Server - Script:349
23:36:06.134 Stage four complete - Server - Script:237
23:36:06.135 You got the pattern correct! - Server - Script:238
23:36:06.135 Triggered (You got the pattern incorrect) - Server - Script:349
(Pressing the first button causes the first two print statements to occur simultaneously in the second output. This is of course, not supposed to happen.
I am aware that the code is horrendously written and not organized at all. Most of it doesn’t contribute to functionality.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.