Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Nil error| Why does this code give me an error?[Solve by self]

Asked by 8 years ago

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

0
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 M39a9am3R 3210 — 8y

Answer this question