Idea The code randomly grabs parts from a model, and spawns them within a given area.
Problem I get this area when I test it, and it happens randomly: attempt to index a nil value
and the error is happens on line 12.
Code:
local treasures = {"AztecMask", "Crown", "DominoCrown", "DominusAureus", "Helmet", "PaintBallMask","Statue"}
local model = game.ReplicatedStorage.TreasureList
local minTime = 1
local maxTime = 1
local xPos = {-6.5, 28.5}
local yPos = {0.5, 0.5}
local zPos = {-22.5, 2.5}
local modelnumber = 0
while wait(math.random(minTime, maxTime)) do
local m = treasures[math.random(1,#treasures)]
local cloney = model:findFirstChild(m):clone()
local x = math.random(xPos[1], xPos[2])
local y = math.random(yPos[1], yPos[2])
local z = math.random(zPos[1], zPos[2])
cloney.Parent = game.workspace
cloney.Position = Vector3.new(x,y,z)
modelnumber = modelnumber + 1
print(modelnumber)
if modelnumber >= 5 then
break
end
end
THANKS

1 comment
Reason is, you're trying use a function with a instance rather than a string. FindFirstChild looks for a object with the name. In short terms, you should be able to change m in line 12 to m.Name