Using a local to define another identifier

Hello
Not really sure with the title as what to call it, but I think people would get the general idea of what this thread is about. It’s a simple thing that I’m sure someone could solve quickly, but I also couldn’t find any other threads about this.

So, I have a system where I want x to be able to define an identifier in y
x is randomly generated through math.Random and is assigned to an IntValue.

Now I would like a script to make it so that the value assigned to “BiomeID” (The IntValue) is replicated to one of the Unions under “SimpleBiomes”. For example, if math.Random assigns a value of 1 to the IntValue, I will be able to idenfity the Union, in this case, “1”.

image

I have created this script so far.
local ChunkGenerationID = script.Parent.BiomeID.Value
game.Workspace.Biomes.SimpleBiomes.

after “SimpleBiomes” I want it to pick the union which was assigned by the BiomeID.

Any help?

If you’re just trying to get the object inside of the SimpleBiomes folder you can do :FindFirstChild() to get the object inside of it.

An Example:

local biome = workspace.Biomes.SimpleBiomes:FindFirstChild(tostring(script.Parent.BiomeID.Value))

The biome variable would hold what you’re looking for.

1 Like

and after I do :FindFirstChild() would I be able to comtinue the idenifier further down?

FindFirstChild by definition returns the first object it finds that matches in name, so you can access the properties of biome with it. Say it had a Value inside, you could find that by using the new biome variable

local someOddValue = biome.variableName.Value -- It can find children inside.

local transparency = biome.Transparency -- you can also get these too.

Perfect. Don’t know why I didn’t think of :FindFirstChild in the first place haha. Cheers.

If you’re feeling really bold you can do this

workspace.Biomes.SimpleBiomes[tostring(script.Parent.BiomeID.Value)]

but for obvious reasons wouldn’t recommend in your use case

This is less cleaner, yes, but it is the fastest way to do:

But if you are a beginner, you should not use this if you not understand it.

Given that OP didn’t think about the FindFirstChild method, I wouldn’t recommend them to use the absolute fastest option.

1 Like