尝试使用 Name 索引空值

我正在创建一个使用远程函数的脚本,但是在 elseif part2.Name==selected.Name 处出现了“尝试使用 Name 索引空值”的错误,以下是脚本代码:

 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
点赞
用户14091631
用户14091631

你的问题可能是,selected 是空的(也许你在调用函数时忘记了传递第三个参数,或者它为 nil)。

2021-08-07 17:30:40