Help making each number appear on a different note of the map

Hey! so im making a challenge for scripting a game in 1 day and i kinda of need help quick, im a pretty advanced scripter

But my problem is: i want to make each number for a random generated code appear on a different note around the map, i already did the random note system and etc but im running into a problem, if i make the number appear on a random note inside a folder it can appear in any note if the note isnt used already

Can anyone help me make that?
My current script

local replicatedstorage = game:GetService("ReplicatedStorage")
local code = replicatedstorage.KeyCodePass

local newcode
newcode = math.random(100000,999999)
code.Value = newcode

local notes = workspace.Keycodes:GetChildren()

for i = 1, #tostring(newcode) do -- i already tried changing a lot of things
	local note
	repeat
		note = notes[math.random(math.max(#notes, 1))]
		if note.Name ~= "Used" then
			note.SurfaceGui.TextLabel.Text = i
			note.Name = "Used"
		end
	until note.Name == "Used"
end

This will probably work for your intended purpose. I tested it on my end based only on what you posted and it worked as intended.

function generateNewCode ()
	local code = math.random (10 ^ (#notes - 1), 10 ^ #notes - 1)
	-- can hard code random limits, but this allows you to just add new notes if you want to increase the code length

	local codeString = tostring (code)
	
	for _,v in pairs (notes) do
		v.SurfaceGui.TextLabel.Text = string.sub (codeString, v.Name, v.Name)
	end
	
	Code.Value = code
	CodePart.SurfaceGui.TextLabel.Text = code
end

image

Only change that you would have to make is that each note needs to be named to the corresponding part of the code that it is for, i.e. - Note 1 needs to be named “1”.

Sorry for the late response, thanks this worked perfectly! :slight_smile: