我的通知系统出现了“尝试调用实例值”的错误
2021-1-2 9:51:28
收藏:0
阅读:186
评论:2
这是代码的两部分:服务器和本地。我正在尝试制作一个系统,将用户的余额从表中存储在其玩家的IntValue中(位于“game.Players”中),然后稍后调用它以检查其是否已更改。如果发生任何事情,通知将通过本地脚本发送到GUI。无论发生什么,通知都不会出现。如果您需要其他东西,我很乐意提供。感谢您的阅读和任何潜在的帮助。这是一个名为Roblox上的Opix Islands游戏,在此我不是专家也不是新手,我只是有点卡住了。
服务器端:
while true do
for i,v in game.Players do --这是出现错误的行。
local tab = nil
for I,V in pairs(_G.GlobalData) do
if V.UserId == v.UserId then
tab = V
end
end
if not v.Bank then
newval = Instance.new("IntValue",v)
newval.Name = "Bank"
wait()
newval.Value = tab.Bank
else
if tab.Bank > v.Bank.Value then
print ("Greater than stored value")
local changedby = tab.Bank - v.Bank.Value
game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,false)
elseif tab.Bank < v.Bank.Value then
print ("Less than stored value")
local changedby = v.Bank.Value - tab.Bank
game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,true)--Player to send to,amount it has changed by,If it has gone down
end
end
end
wait()
end
和本地脚本:
game.ReplicatedStorage.Notif.Return.OnClientEvent:Connect(function(Change,Down)
if Down == false then
local Notification = script.Parent.NotificationExample:Clone()
Notification.Name = "Notification"
Notification.Parent = script.Parent
Notification.Text = "您的银行账户余额刚刚增加了: £"..Change
print ("Bank account Increased by:"..Change)
Notification.Visible = true
print ("通知应该可见")
wait(3)
Notification:Destroy()
print ("通知应该消失了!")
elseif Down == true then
local Notification = script.Parent.NotificationExample:Clone()
Notification.Parent = script.Parent
Notification.Name = "Notification"
Notification.Text = "您的银行账户余额刚刚减少了: £"..Change
print ("Bank account decreased by:"..Change)
Notification.Visible = true
print ("通知应该可见")
wait(3)
Notification:Destroy()
print ("通知应该消失了!")
end
end)
非常感谢。
点赞
用户13578703
while true do
for i,v in pairs(game.Players:GetChildren()) do --这行有错误
local tab = nil
for I,V in pairs(_G.GlobalData) do
if V.UserId == v.UserId then
tab = V
end
end
if not v.Bank then
newval = Instance.new("IntValue",v)
newval.Name = "Bank"
wait()
newval.Value = tab.Bank
else
if tab.Bank > v.Bank.Value then
print ("Greater than stored value")
local changedby = tab.Bank - v.Bank.Value
game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,false)
elseif tab.Bank < v.Bank.Value then
print ("Less than stored value")
local changedby = v.Bank.Value - tab.Bank
game.ReplicatedStorage.Notif.Return:FireClient(v,changedby,true)--玩家送到,它已改变的数量,如果它已下降
end
end
end
wait()
end
2021-01-02 13:38:36
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?


看起来
game.Players不是一个函数。像这样
for i,v game.Players do end是行不通的。
根据 Lua 手册:
在你的情况下,Lua 将把
game.Players视为迭代器函数,因为这是你提供的explist中的第一个(也是唯一的)元素。当调用它时,它会导致观察到的错误,因为它不是函数值。你可能想要做这样的事情:
for i,v in ipairs(game.Player:GetChildren()) do end