Hi! I’m attempting to create a script that selects one of several random Decals -
I used to have a method of doing this, however I cannot for the life of me remember how I did it.
The way I had done it before didn’t require me to name the Decals different number and do a math.random etc etc. It simply let me get one of the Children at random.
I believe it to have been along the lines of:
local faces = game.Workspace.Faces:GetChildren()
local Randomface = 1,#faces
But I’m not certain what so ever.
Is anyone able to help rejog my memory on this one? :L
First we’ll need to create a table of your decals.
local Decals = Faces_Folder:GetChildren() --Creates a table of all the children of your faces folder
local Decals_Index = 1 --Change this to whatever index you want from our newly created table
Decals[Decals_Index].Parent = game.Workspace.Decal_Part --Do something with the indexed decal
If you want to iterate slowly though the list, you can use the following:
local faces = game.Workspace.Faces:GetChildren()
local cur = 1
local function chooseDecal()
local obj = faces[cur]
cur = cur + 1
if cur>#faces then
cur = 1
end
return obj
end
print(chooseDecal()) --Prints first object of faces
print(chooseDecal()) --Prints second object of faces
print(chooseDecal()) --If only 2 objects were in faces, this would print the first one