I can’t really explain it in the title, but you should hopefully be able to see what I’m trying to do
if tilepath ~= nil then local clonetile = tiles[tostring(tilepath)]:Clone()
The tilepath is grabbed from a table I have Table:
["rocksvariant1"] = { ['chance'] = 20, ['path'] = 'RocksVariant1'
The script knows what tiles are Reference:
local tiles = script:WaitForChild("ProceduralForestTiles"):GetChildren()
and If I print the tilepath variable i get Output:
Rocksvariant1
So how would I use the variable as a path, I’m trying it the way I have it now but I’m getting this error
[05:17:28.106 - Workspace.CurrentMap.ProceduralGeneratorScript:134: attempt to index nil with 'Clone'
Basically im trying to sort of make it say “tiles.RocksVariant1:Clone” Without it actually saying that.
Thanks.
The problem with the code is the fact that you get the children of the tiles object. The reason this does not work is because you are trying to index an array with a dictionary key. So your new tiles variable would look like:
local tiles = script:WaitForChild("ProceduralForestTiles")
Whenever I do something like this in my scripts, I always use object:FindFirstChild()
and check to see if it is actually there. What I would also suggest:
local clonetile = tiles:FindFirstChild(tilepath) if clonetile then local clone = clonetile:Clone() end
You could also get rid of your intial if statement in this situation.
Hope this helps!