如何在Roblox Lua中向DataStore添加表格?
2019-7-13 0:40:3
收藏:0
阅读:128
评论:1
目标:制作一个帽子库存系统,保存所购买的帽子并将其添加到个人库存中。
目前状态:我有一个IntValue,在玩家(非角色)加入游戏时,它会被添加到玩家身上。这个IntValue的名字是“CurrentHat”,它的值设置为玩家上次穿的保存帽子。之后它会等待在角色加载时通过从ServerStorage获取CurrentHat的值将帽子添加到玩家的头上。然后,如果CurrentHat的值发生变化,就会将其连接到添加玩家帽子函数并连接到数据存储。下面是代码的一部分,可以添加数据到游戏中,我认为库存数据应该添加到游戏中。所有被注释掉的内容都是我尝试过但失败了。
function playeradded(player)
print("hello")
player:LoadCharacter()
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local hat = Instance.new("StringValue")
hat.Name = ("CurrentHat")
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = leaderstats
leaderstats.Parent = player
hat.Parent = player
hat.Value = ds2:GetAsync(player.UserId) or math.floor(math.random(0,1))
--table.insert(hattable, hat.Value)
-- ds3:SetAsync(player.UserId,hat.Value)
--for index,value in pairs (hattable) do
-- ds3:UpdateAsync(index, function() return value end)
--end
--print(hattable[1])
--print(ds3)
local playerHat = hat.value
hat.Changed:connect(function()
ds2:SetAsync(player.UserId,hat.Value)
--ds3:SetAsync(player.UserId,table.insert(hat.Value))
--print(ds3)
end)
coins.Value = ds1:GetAsync(player.UserId) or 0
ds1:SetAsync(player.UserId,coins.Value)
我想要实现的一个很好的示例是Roblox游戏SwordBurst的库存系统,只不过只有服装。我希望能够调用玩家的数据存储,如果库存中包括该帽子,则在他们的库存中显示它,以允许他们把它戴在头上。如果有人能帮我,那就太棒了!
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 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 代码?

你不能在
:SetAsync()中保存表格,但是可以在:UpdateAsync()中保存。所以如果你按照以下方式操作,它应该可以工作:local clothing = {"帽子1","衬衫1","等等"} local datastore = game:GetService("DataStoreService"):GetDataStore("Clothing") datastore:UpdateAsync("A_key",function() return clothing end)这些变量只是示例,请相应更改一些内容。