How do I fix this counter/click parts script?

So I had this script working for something else but I wanted to edit it a bit, but the issue is I’m unsure how to make it work with the new edits I want.

So initially, the script was supposed to work like this: You had a specific order for parts you needed to click in a specific order for something to happen in-game after clicking all those buttons in order.

Here is the script:

local correctPattern = {"Bowler1", "Bowler2", "Bowler3", "Bowler4", "Bowler5", "Bowler6", "Bowler7", "Bowler8", "Bowler9", "Bowler10", "Bowler11", "Bowler12", "Bowler13", "Bowler14", "Bowler15", "Bowler16", "Bowler17", "Bowler18", "Bowler19", "Bowler20", "Bowler21", "Bowler22", "Bowler23", "Bowler24", "Bowler25", "Bowler26", "Bowler27", "Bowler28", "Bowler29", "Bowler30", "Bowler31"} -- etc, the correct pattern.
local current = {} -- table to hold what the user has clicked so far
local count = 1
local buzzer = game.Workspace.Buzzer
local counter = game.StarterGui.CounterGUI.Frame.Counter

-- loop through all the tiles. You should put every "bowler" inside a folder in the
-- workspace called "Bowlers", as it's setup in the script below.
for i,part in pairs(game.Workspace.Bowlers:GetChildren()) do
	part.ClickDetector.MouseClick:Connect(function()
		table.insert(current, part.Name)
		if current[#current] == correctPattern[count] then
			print("correct tile")
			count += 1
			buzzer:Play()
			counter.Text = count
			
		else
			print("wrong tile")
			count = 1
			current = {}
		end
		if count - 1 == #correctPattern then

			print("player clicked all tiles correctly")
			game.Workspace.ForceField1:Destroy()
			game.Workspace.ForceField2:Destroy()
			game.Workspace.ForceField3:Destroy()
			game.Workspace.ForceField4:Destroy()
			game.Workspace.ForceField5:Destroy()
			game.Workspace.ForceField6:Destroy()
			game.Workspace.ForceField7:Destroy()
			game.Workspace.ForceField8:Destroy()
			game.Workspace.ForceField9:Destroy()
			
		end
	end)
end

Now I wanted to edit the script to be like this: I don’t want it to be “you have to click the buttons in order” I just want it to be so that you only need to click the buttons, but not in order. Also, I added a GUI counter (seen in the picture below) which is supposed to count for each time you click the buttons, so for example if you click one of the buttons it will go from 0 to 1, basically a counter. I couldn’t figure out how to make it work like that either.

I would really appreciate any help to make this work!

Here is the picture of the counter I mentioned before:
image

Here it is in Explorer under StarterGui:
image

1 Like

Also, I’m not sure if it helps, but the game is 1-player-server-only.

Referencing the CounterGUI as game.StarterGui.CounterGUI.Frame.Counter won’t work because once the game starts, all contents of StarterGui are moved to PlayerGui, so you will need to reference it as:

(if Local Script):

game.Players.LocalPlayer.PlayerGui.CounterGUI.Frame.Counter

(Server script):

part.ClickDetector.MouseClick:Connect(function(plr)
plr.PlayerGui.CounterGUI.Frame.Counter
end)

Hope this helps with the counter Gui!

1 Like

It gives me this error in output:

try doing

game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("CounterGUI"):WaitForChild("Frame"):WaitForChild("Counter")
1 Like

Seems to be working, thank you!

Praying someone helps with the rest of the code :smiling_face_with_tear:

1 Like

You could remove the functions that check the correct pattern and the correct pattern table. Im not great with tables, so i’m not sure if my solution will work but its worth a shot.

1 Like
local correctPattern = {"Bowler1", "Bowler2", "Bowler3", "Bowler4", "Bowler5", "Bowler6", "Bowler7", "Bowler8", "Bowler9", "Bowler10", "Bowler11", "Bowler12", "Bowler13", "Bowler14", "Bowler15", "Bowler16", "Bowler17", "Bowler18", "Bowler19", "Bowler20", "Bowler21", "Bowler22", "Bowler23", "Bowler24", "Bowler25", "Bowler26", "Bowler27", "Bowler28", "Bowler29", "Bowler30", "Bowler31"} -- etc, the correct pattern.

i have questions for the ‘Correct patterns’
does it stop at 31? and what are the part’s names?

there’s definitely a way to shorten the whole script

1 Like

Yes, so the way I made it is:

There are 31 levels in the game, in each level I have hidden a Bowler hat, and you need to click “find” those 31 bowler hats in each level so that when you do find them all, something will happen at the end “at level 31” for finding them all.

All of them are inside a folder in workspace called “Bowlers” btw.

The parts’ names are the same as you see in the “correctPattern” table, they’re called Bowler1, Bowler2, etc…

how would you ever click a wrong tile?

1 Like

The script was initially made for something else “A chess board where you had to click certain tiles in a specific order to open a door, all of this is in a different game”, but I decided to use the same script and edit it a bit to make it work with what I’m doing now “another totally different game”, but I’m unsure how.

I just wanted to make the script so that you basically have to click “find” all the Bowlers in the game “doesn’t have to be in order” for you to be able to open a door at the end of the game, while the counter GUI increases +1 each time you click “find” a Bowler.

well if you don’t want it to be in order you could remove the “current” stuff entirely

local Buzzer = workspace:WaitForChild("Buzzer")
local Bowlers = workspace:WaitForChild("Bowlers"):GetChildren()
local Counter = script.Parent -- just put the script inside the Counter
local ForceFields = workspace:WaitForChild("ForceFields"):GetChildren() -- make a folder of forcefields instead of destroying them individually

count = 0

for _, Tile in ipairs(Bowlers) do
  Tile.ClickDetector.MouseClick:Once(function()
    Buzzer:Play()
    count += 1
    Counter.Text = count
    print("+1 Tile.")
		
    if count == #Bowlers then
      for _, Field in ipairs(ForceFields) do
        Field:Destroy()
      end
      print("Player clicked all tiles.")
    end
  end)
end
1 Like

i just realized you might be able to just click 1 tile constantly to pass

For some reason, it doesn’t seem to work, when I click the Bowler it doesn’t increase the counter nor does it print/give me an error or anything in output.

you did make a folder for the force fields right

1 Like

My bad forgot to do that!

It seems to work after adding a folder for forcefields, but yes as you said the issue is that you can click it infinitely and the counter would still keep going.

Also noticed that when you die/reset the counter resets back to 0, is there a way to fix that too? So that the counter stays even if you die/reset multiple times while still in-game.

but yes as you said the issue is that you can click it infinitely and the counter would still keep going.

i had edited the reply, i’m not sure if you already copied it before i edited it but i changed two things

count = 1 --> 0
...
MouseClick:Connect(function() --> MouseClick:Once(function()

Also noticed that when you die/reset the counter resets back to 0, is there a way to fix that too? So that the counter stays even if you die/reset multiple times while still in-game.

yes go to the ScreenGui that’s holding the counter you can disable ResetOnSpawn

1 Like

I honestly can’t thank you enough for helping me solve this issue & for being patient and teaching me how to fix this step by step.

Everything seems to be working perfectly as I wanted, thank you so so much!!! :heart:

1 Like

no problem :+1:

charcharcharchar

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.