【问题标题】:What does "attempt to index nil with 'WaitForChild'" mean?“尝试用'WaitForChild'索引nil”是什么意思?
【发布时间】:2021-03-30 20:04:56
【问题描述】:
script.Parent.MouseButton1Click:connect(function()
    local RS = game:GetService("ReplicatedStorage")
    local item = RS:WaitForChild("Pencil")
    local price = 350
    local player = game.Players.LocalPlayer
    local stats = player:WaitForChild("leaderstats")
    
    if stats.Strength.Value>=price then
        stats.Strength.Value = stats.Strength.Value - price
        local cloned = item:Clone()
        cloned.Parent = player.Backpack
        cloned.Parent = player.StarterGear
    end
end)

我正在尝试建立一个商店,它在第 6 行出现“尝试使用 'WaitForChild' 索引 nil”:

local stats = player:WaitForChild("leaderstats")

我完全复制了视频的内容,视频没有问题,显然播放器没有价值,即使我们只在上面设置了一行

【问题讨论】:

  • 您无法在 ServerScript 中获取 LocalPlayer;再试一次

标签: lua roblox


【解决方案1】:

表示你在索引一个nil的值,也就是说player的值是nil,也就是说前面的like上的game.Players.LocalPlayer返回nil。为什么那是你需要弄清楚的,因为没有太多可做的。

example 表明它应该是local player = game:GetService("Players").LocalPlayer,所以您可能想尝试一下。

【讨论】:

  • 我尝试输入您告诉我的内容,但出现与以前相同的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-23
  • 2010-09-16
  • 2021-03-29
  • 2019-03-30
  • 2016-07-14
  • 2022-12-24
相关资源
最近更新 更多