尝试在 roblox studio 中使用 'leaderstats' 索引 nil

attempt to index nil with 'leaderstats' in roblox studio

local garbage = game.Teams["Glizzy Garbage"]
local player = game.Players.LocalPlayer

if player.leaderstats.Pounds.Value <= 1000 then  --this is the line that the output is detecting the error
    player.Team = garbage
end

我正在努力做到这一点,当玩家达到一定数量 'pounds' 时,他们将自动获得掷骰。我搜索了许多 youtube 视频,但没有找到解决方法或替代方法,而且我不确定为什么这不起作用。该脚本位于工作区中。感谢所有帮助。

LocalPlayer 对象仅在 LocalScripts 中公开。因为您在工作区中使用脚本,所以您必须以另一种方式访问​​ player 对象。在 Pounds 值更改时触发的函数中处理这种逻辑也是一个好主意。

尝试使用 game.Players.PlayerAdded 信号:

local garbage = game.Teams["Glizzy Garbage"]

game.Players.PlayerAdded:Connect(function(player)
    local Pounds = player.leaderstats.Pounds
    Pounds.Changed:Connect(function(value)
        if value <= 1000 then
            player.Team = garbage
        end
    end)
end)

我的只是

local plrStage = plr.leaderstats.Stage.Value