What do you want to achieve? I am making a puzzle with pipes and 5 valves, and if you click the valves in the wrong order, it plays a fail sound and you have to hit a button to reset it and try again. If you get it correct, it plays a success sound, the reset button is disabled, and a BoolValue is set to true. (Sorry if this is a lot.)
What is the issue? I’m quite new to scripting, and I can’t figure out how to make it check if you’re clicking the valves in the right order. I also cannot start scripting the reset button, because I need the valves to work first.
What solutions have you tried so far? I’ve tried making my own script and looking for any help on the DevForum, but couldn’t find anything.
You would need to use a for loop to detect when each valve is clicked and detect whether or not the order is correct, I would put the correct order of valves into a table and the order the player puts them ex:
correctOrder = {5, 4, 3, 2, 1}
playerOrder = {3, 2, 5, 4, 1}
After all valves are clicked compare both tables to check if they’re the same
local rightOrder = {1,2,3,4,5}
local order = {} -- player's order
local valves = { -- Make sure these are paths to the valve
[1] = ... ,
[2] = ... ,
[3] = ... ,
[4] = ... ,
[5] = ... ,
}
for index, valve in pairs(valves) do
local clickDetector = valve:WaitForChild("ClickDetector") -- make sure this is correct
clickDetector.MouseClick:Connect(function()
if rightOrder[#order + 1] == index then
-- correct valve, you can turn this or whatever
table.insert(order, index)
if #order >= #rightOrder then
-- open a door or something, the whole order is correct
end
else order = {} end -- reset if you made any mistake, turn them all back
end)
end
Actually you can remove playerOrder and call it amountCorrect, set it to 0 by default then it’d look smth like this:
local rightOrder = {1,2,3,4,5}
local amountCorrect = 0
local valves = { -- Make sure these are paths to the valve
[1] = ... ,
[2] = ... ,
[3] = ... ,
[4] = ... ,
[5] = ... ,
}
for index, valve in pairs(valves) do
local clickDetector = valve:WaitForChild("ClickDetector") -- make sure this is correct
clickDetector.MouseClick:Connect(function()
if rightOrder[amountCorrect + 1] == index then
-- correct valve, you can turn this or whatever
amountCorrect += 1
if amountCorrect >= #rightOrder then
-- open a door or something, the whole order is correct
end
else amountCorrect = 0 end -- reset if you made any mistake, turn them all back
end)
end
You’d need to use the 1st code then, and change the part in the middle, oh and do you want it to reset after you get all 5 wrong?
local rightOrder = {1,2,3,4,5}
local order = {} -- player's order
local amountCorrect = 0
local valves = { -- Make sure these are paths to the valve
[1] = ... ,
[2] = ... ,
[3] = ... ,
[4] = ... ,
[5] = ... ,
}
for index, valve in pairs(valves) do
local clickDetector = valve:WaitForChild("ClickDetector") -- make sure this is correct
clickDetector.MouseClick:Connect(function()
table.insert(order, index) -- save the data
if rightOrder[#order + 1] == index then
-- correct valve, you can turn this or whatever
amountCorrect += 1
if amountCorrect == #rightOrder then
-- you got the combination correct
elseif #order >= #rightOrder
-- reset it if you have made 5 mistakes
amountCorrect = 0
order = {}
end
end -- reset if you made any mistake, turn them all back
end)
end
local resetButton = ... -- Path to reset clickdetector
resetButton.MouseClick:Connect(function()
amountCorrect = 0
order = {}
end)
Sorry for not being very specific. I want it so that if you click on one of the valves when you aren’t supposed to, the puzzle essentially stops working until you click the reset button, which will start it over. It doesn’t need any automatic resets, only the button should reset it.
local rightOrder = {1,2,3,4,5}
local order = {} -- player's order
local amountCorrect = 0
local valves = { -- Make sure these are paths to the valve
[1] = ... ,
[2] = ... ,
[3] = ... ,
[4] = ... ,
[5] = ... ,
}
for index, valve in pairs(valves) do
local clickDetector = valve:WaitForChild("ClickDetector") -- make sure this is correct
clickDetector.MouseClick:Connect(function()
if amountCorrect == -1 then return end -- if -1 then it broke (because 1 wrong)
table.insert(order, index) -- save the data
if rightOrder[#order + 1] == index then
-- correct valve, you can turn this or whatever
amountCorrect += 1
if amountCorrect == #rightOrder then
-- you got the combination correct
end
else amountCorrect = -1 -- if -1 then you cannot continue
end
end)
end
local resetButton = ... -- Path to reset clickdetector
resetButton.MouseClick:Connect(function()
amountCorrect = 0
order = {}
end)
``