【问题标题】:Attempt to Index nil with Name尝试使用名称索引 nil
【发布时间】:2021-10-10 20:35:46
【问题描述】:

我正在使用远程函数创建一个脚本,但在 elseif part2.Name==selected.Name 上写着:“尝试用名称索引 nil”这是脚本:

 game.ReplicatedStorage.Events.PlaceBlock.OnServerInvoke= function(player,pos,selected)
        for i,part2 in ipairs(parts:GetChildren()) do
            if part2== nil then
                partPlace= parts.BasicPart
            elseif part2.Name==selected.Name then
                partPlace = selected:Clone()
            end
        end
        partPlace.CFrame = CFrame.new(math.ceil(pos.X), math.ceil(pos.Y)+2, math.ceil(pos.Z))
        partPlace.Orientation = Vector3.new(0,0,0)
        partPlace.Parent = player.Plate.Value.Parts
        partPlace.Owner.Value=player
    end

【问题讨论】:

  • 看到你对part2进行nil检查,你的问题是selected = nil
  • Seth OwO,你能分享你打电话给PlaceBlock:InvokeServer(pos, selected)的代码吗?

标签: lua roblox


【解决方案1】:

您的问题可能是,选择的是 nil(也许您在调用函数时忘记传递第三个参数,或者它是 nil)。

【讨论】:

    猜你喜欢
    • 2020-08-16
    • 2021-09-04
    • 2022-01-05
    • 2021-08-02
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 1970-01-01
    相关资源
    最近更新 更多