Hello,
I am trying to make a random ore spawning system and I’m running into some issues. I’m storing the possible ores that can spawn within a table by its name. The issue that I’m running into is that when I try to clone the ore from ReplicatedStorage using the name from the table, it keeps returning nil. The ore is part of the table, so that’s not the issue.
local possibleOres = {}
local rn = math.random(1, 500)
if (possibleOres[rn] == nil) then
local ore = game.ReplicatedStorage.Ores.stone:Clone()
ore.Position = newPos
ore.Parent = workspace.Blocks
ore.Name = ore.Name .. counter
counter += 1
else
if (game.ReplicatedStorage:FindFirstChild("Ores"):FindFirstChild(possibleOres[rn])) then
local block = game.ReplicatedStorage.Ores:FindFirstChild(possibleOres[rn]):Clone() -- This is the issue line!
block.Position = newPos
block.Parent = workspace.Blocks
block.Name = block.Name .. counter
counter += 1
else
print("[NOTICE: Unable to generate ore!")
Generate(pos)
end
end
Is there a possible better way to do this / a right way?
Thanks!