尝试索引 upvalue 'plr'(nil 值)

我尝试修复错误,但没有成功,请帮我修复 这是脚本:

local plr = game.Players.LocalPlayer

    local items =game:GetService("ReplicatedStorage").Items

    game:GetService("ReplicatedStorage").ClientPlaced.OnServerEvent:connect(function(player, itemName, location)

        local itemTemplate = items:FindFirstChild(itemName)

        if (itemTemplate) then
            local item = itemTemplate:clone()
            item.Parent = workspace:FindFirstChild(plr.Name .. "Base").ItemHolder
            item:SetPrimaryPartCFrame(location[1])
        end

    end)
点赞
用户2858170
用户2858170

错误信息告诉你,在定义函数的范围内,你的本地变量 plrnil,因此你可能不能在函数内部对它进行索引。

local plr = game.Players.LocalPlayer

很明显,game.Players.LocalPlayernil

plr.Name 导致了错误。

由于函数有一个 player 参数,这很可能是你想要索引的变量。但是,由于你没有提供所有信息,我无法确定。

尝试使用 player.Name

2017-11-20 06:05:50