Hey, What i’m trying to do is a random generated code on a text label then set a attribute in a door. but the problem is that every number is separated so i only get one digit… i tried to google and i don’t see something that helps me here my code:
local Code1 = math.random(1,9)
local Code2 = math.random(1,9)
local Code3 = math.random(1,9)
local Code4 = math.random(1,9)
local CodeFolder = workspace.CodeParts
local DoorCode = workspace.Door.DoorCode
local Code = {
Digit1 = tostring(Code1),
Digit2 = tostring(Code2),
Digit3 = tostring(Code3),
Digit4 = tostring(Code4)
}
for i,v in pairs(CodeFolder:GetChildren()) do
if v:IsA("Part") then
GeneratedCode = math.random(#Code, 9)
v.SurfaceGui.CodeText.Text = GeneratedCode
print(GeneratedCode)
end
end
DoorCode:SetAttribute("DoorCode", GeneratedCode)
-- Empty string
code = ""
-- Loop 9 times, from 1 - 10; change 10 to how long you want your code to be
for i = 1, 10, 1 do
-- Concatenate the current value of code with a random number
code = code .. tostring(math.random(1, 9))
end
-- Cast the code to an int
code = tonumber(code)
-- Set the code attribute of the object to the generated code
obj:SetAttribute("Code", code)