Wanting to modify a hidden door with hidden hint that is in order

Hello! I wanted to modify this hidden door and gave it hints in order

What I mean by this is that I wanted to create a passcode door with hints being hidden around the map. I wanted to create where player will know which order to put the code in.

I wanted to add each letter before each code so player could know which order to put the code in

For example:

Explanation for the image above

  • So A came before any other letters in the alphabet so the code would be 5 first

  • Then I will come after A so 0 would be second and etc…

Here is the script (This script is in StarterGui and is a local script):

-- Created by TDK on 10/3/2019
local Code = math.random(1111,9999)
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Door = workspace:WaitForChild("KeypadDoor").Parts.Door
local Buttons = workspace:WaitForChild("KeypadDoor").Buttons
local InfoParts = workspace:WaitForChild("KeypadDoor").InfoParts
local Display = workspace:WaitForChild("KeypadDoor").Display.Display.Hint
local CurrentInput = ""

-- Setup Hint UI
for i,v in pairs(InfoParts:GetChildren()) do
	local CodeString = tostring(Code)
	InfoParts[tostring(i)].Hint.Code.TextLabel.Text = string.sub(CodeString,i,i)
	RunService.Stepped:Wait()
end

-- Setup Door Tween
local OriginalPosition = Door.CFrame
local OpenPosition = Door.CFrame * CFrame.new(-4.5,0,0)
local OpenGoal = {}
local CloseGoal = {}
OpenGoal.CFrame = OpenPosition
CloseGoal.CFrame = OriginalPosition
local Info = TweenInfo.new(1, Enum.EasingStyle.Bounce)
local DoorOpen = TweenService:Create(Door,Info,OpenGoal)
local DoorClose = TweenService:Create(Door,Info,CloseGoal)

-- Setup Button Presses
for i,v in pairs(Buttons:GetChildren()) do
	v.ClickDetector.MouseClick:Connect(function()
		local OriginalCFrame = v.CFrame
		local ButtonInput = v.Hint.TextLabel.Text
		v.CFrame = v.CFrame * CFrame.new(0,0,-0.1)
		for i=1,10 do
			RunService.Stepped:Wait()
		end
		v.CFrame = OriginalCFrame
		if string.lower(ButtonInput) == "enter" then
			if CurrentInput == tostring(Code) then
				Display.TextLabel.Text = "CORRECT"
				CurrentInput = ""
				DoorOpen:Play()
				for i=1,360 do
					RunService.Stepped:Wait()
				end
				Display.TextLabel.Text = ""
				DoorClose:Play()
			elseif CurrentInput ~= tostring(Code) then
				Display.TextLabel.TextColor3 = Color3.fromRGB(255, 95, 84)
				Display.TextLabel.Text = "INCORRECT"
				CurrentInput = ""
				for i=1,60 do
					RunService.Stepped:Wait()
				end
				Display.TextLabel.Text = ""
				Display.TextLabel.TextColor3 = Color3.fromRGB(85, 255, 127)
			end
		elseif string.len(CurrentInput) < 4 then
			CurrentInput = CurrentInput..ButtonInput
			Display.TextLabel.Text = CurrentInput
		end
	end)
end

Please note that I found this model on the DevForum:

Please tell me how I could do this! If you have any questions please tell me in the comment below!

So what are you needing help with?

I need help with putting a random alphabet letter infront of each number when the codes are generated so player could know which order to put the numbers in.

You can use this to referenence what I’m talking about…

why random?
if you want to show the hints in order you could do something like this:

hintcycle = 1
script.parent.clickdetector.mouseclick:connect(function()
if hintcycle = 1 then
--stuff
hintcycle = hintcycle + 1
end
--and do the rest with hintcycle, make it an int value if you want it to stay after the script is done
end)

No like, I want them to generate a random letter then a number so player would know which order to put the code in

if you want to add letters simply use math.random and add every letter you wanna add, and make the text that, for example:

local letter = math.random(a,b,c,d,e,f,g)
print(letter)

so like an random letter and a defined number? what does random letter do with order…i don’t think i understand

For example:

A came first so 5 would be the first number

I came after A so 0 would be the second number

N came after I so 9 would be the third number

and lastly W cam last so 4 would be the last number

oh i see, could you show me all the hint ui parts so it dosn’t get confused with the keypad part?

Here you go!

Step one: Generate a code

Step two: Make two tables for the alphabet
{"A", "B", "C", etc.}

Step three: Select 4 random letters from the first table. After selecting them, remove them from the table

Step 4: Put the letters in order. Loop through the second table, find the index of each letter by matching each of the 4 letters. You can then create a new table with the letters in order.

Step 5: Pair the letters with the numbers

(I will work on an example to show you because it might seem hard to understand)

1 Like

What do you mean by second table?

if you want the letters to be defines you could just do some simple transparentcy changing using the varibles, if you want truly random letters, then it will be varibles combined with the math.random, you should change the info parts names into word numbers like one because .“number” means something else too

local parts = game.workspace.InfoParts
wait(5)
parts.One.Code.Textlabel.Text = " "..math.Random(a,b,c,d,e,f,g).."5"
wait(1)
parts.Two.Code.Textlabel.Text = " "..math.Random(a,b,c,d,e,f,g).."0"
wait(1)
parts.Three.Code.Textlabel.Text = " "..math.Random(a,b,c,d,e,f,g).."9"
wait(1)
parts.Four.Code.Textlabel.Text = " "..math.Random(a,b,c,d,e,f,g).."4"

this is just an example of what you could do,im pretty sure math.random don’t accept letters but meh

This is a simple way to generate ‘One letter One number’ form if I understood clearly:

function GenerateCode(nubmer)
	local Random = Random.new()
	local randomAlphabet = string.char(Random:NextInteger(65, 90))
	return tostring(nubmer)..randomAlphabet
end

This uses ASCII code ranging from 65 to 90, which is for from capital A to capital Z.

2 Likes

But will that be transfered into numbers if it appear on the Gui?

No, it will be transferred as a capital letter that corresponds to the generated number in ASCII code

You might take a look at:

Ohh right, thank you! But how would i both display a random number and random letter on the gui?

You’re welcome! As you can see in this piece of the code:

It returns the mixture of alphabet and number.

You could simply change text value to the function’s return value i.e.:

-- Setup Hint UI
function GenerateCodeAlphabetically(code)
	local alphabetStorage = {}
	local Random = Random.new()

	local function alphabetGen()
		local t = {(string.byte(alphabetStorage[#alphabetStorage] or "A")), 90-(#tostring(code)-#alphabetStorage)+1}

		local randomAlphabet = string.char(Random:NextInteger(t[1], t[2]))
		for i, v in next, alphabetStorage do
			if v == randomAlphabet then
				alphabetGen()
				return
			end
		end
		table.insert(alphabetStorage, randomAlphabet)
	end

	repeat
		alphabetGen()
	until #alphabetStorage == #tostring(code)

	for i, v in next, alphabetStorage do
		alphabetStorage[i] = v..tonumber(string.sub(code, i, i))
	end

	return alphabetStorage
end

local codeTable = GenerateCodeAlphabetically(Code)

for i,v in pairs(InfoParts:GetChildren()) do
	InfoParts[tostring(i)].Hint.Code.TextLabel.Text = codeTable[i]
	RunService.Stepped:Wait()
end

Any questions regarding it are welcomed!

1 Like

Thank you again but I tried this but the numbers are before the letters and I want the letters to be before the numbers…
image

My bad on this, you should change this to

return tostring(nubmer)..randomAlphabet

this one below

return randomAlphabet..tostring(nubmer)
1 Like