为什么会出现错误信息:“尝试索引空值'Position' ”?

我不知道这里发生了什么。我正在尝试生成随机地形作为一个测试,这段代码是我其中的一个实验(我之后会添加曲率的代码),但它显示“尝试索引空值'Position'”并且我不知道如何修复它。

local Block = game.ReplicatedStorage.Auto_generated
local Plosition = 1
local Line = 1
local Lite = 1

print('1')
Block.Position = Vector3.new(251,35,261)
BlockClone.Position = Vector3.new(Line,pos,Lite)

while Plosition <= 100 do
    print('2')
    BlockClone = Block:Clone()
    BlockClone.Parent = game.Workspace
    pos = math.random(0,10)
    BlockClone.Position = Vector3.new(Line,pos,Lite)
    Line = Line + 10
    Plosition = Plosition + 1
    if Line == 10 then
        Lite = Lite + 10
        print('3')
    end
    if Line == 20 then
        Lite = Lite + 10
    end
    if Line == 30 then
        Lite = Lite + 10
    end
    if Line == 40 then
        Lite = Lite + 10
    end
    if Line == 50 then
        Lite = Lite + 10
    end
    if Line == 60 then
        Lite = Lite + 10
    end
    if Line == 70 then
        Lite = Lite + 10
    end
    if Line == 80 then
        Lite = Lite + 10
    end
    if Line == 90 then
        Lite = Lite + 10
    end
    wait(1)
end
点赞
用户1296374
用户1296374

在这个 while 循环的上一行中,BlockClone 是未定义的。

你只在下面两行代码中定义了它:

BlockClone = Block:Clone()

BlockClone.Position = Vector3.new(Line,pos,Lite)

2020-05-01 20:15:40
用户14461945
用户14461945

我认为问题在于代码中的:Plosition = 1,代码在顶部。

2020-10-16 10:37:46