【问题标题】:Why is there an error saying 'attempt to index nil with 'Position''?为什么会出现错误提示“尝试使用 'Position' 索引 nil”?
【发布时间】:2020-10-17 19:03:49
【问题描述】:

我不知道这里发生了什么。我正在尝试将随机生成的地形作为测试,此代码是我的实验之一(稍后我将添加曲率代码),但它说“尝试使用“位置”索引 nil”并且我不知道如何修复它。

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

【问题讨论】:

    标签: error-handling lua roblox


    【解决方案1】:
    BlockClone.Position = Vector3.new(Line,pos,Lite)
    

    在那一行(在 while 的上方),BlockClone 是未定义的。

    你只在下面两行定义它

    BlockClone = Block:Clone()
    

    【讨论】:

      【解决方案2】:

      我认为是因为代码:Plosition = 1 在顶部

      【讨论】:

      • 虽然是拼写错误,但后面的代码中使用了相同的标识符。
      猜你喜欢
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 2013-03-07
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      相关资源
      最近更新 更多