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
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!
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)
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)
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
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.
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