lua - 尝试在 roblox studio 中使用“leaderstats”索引 nil
问题描述
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
我试图让它在玩家达到一定数量的“磅”时,他们将自动获得滚动。我搜索了许多 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)
推荐阅读
- python - 如何在 csv 文件中使用 python 中的 if 语句比较时间
- python - 如何在 Pygame 中测试碰撞?
- javascript - 如何随机制作 *ngFor 显示?
- python-3.x - font.getsize() 似乎不适用于参数内的“\n”(新行)
- java - Spring - 上传文件不能大摇大摆地工作
- sql-server - 我可以将同一张表的两个更新语句放在一个条件中吗?
- python - groupby 上的指数加权函数
- javascript - 如何使用javascript dom编写多个div
- c++ - 主程序退出后停止子进程c ++
- powershell - 从 CSV 添加 NTFS 访问