如何在Roblox中使用dev product制作持续30秒的护盾?
2021-2-28 2:30:6
收藏:0
阅读:146
评论:1
当有人购买我的dev product时,我希望他们能获得一个持续30秒的可见护盾。
这是我尝试过的代码:
local mpService = game:GetService("MarketplaceService")
local Debris = game:GetService("Debris")
local function giveForcefield(player, duration)
local character = player.Character
if character then
local forceField = Instance.new("ForceField")
forceField.Visible = true
forceField.Parent = character
if duration then
Debris:AddItem(forceField, duration)
end
end
end
mpService.ProcessReceipt = function(purchaceInfo)
local plr = game:GetService("Players"):GetPlayerByUserId(purchaceInfo.PlayerId)
if purchaceInfo.ProductId == xxxxxxx then
game.Players.PlayerAdded:connect(function(plr)
repeat wait() until plr.Character
local char = plr.Character
giveForcefield(plr, 30)
local forceField = Instance.new("ForceField")
forceField.Visible = true
forceField.Parent = char
end)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
我可以购买dev product,但是代码运行后什么也不发生。 我尝试过很多事情但我有点迷惑。 请帮帮我。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 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 代码?

你编码创建和销毁 ForceField 的两种方式都是有效的,但正如 Piglet 建议的那样,你的代码根本没有被调用。你的代码是这样的,“一旦有人购买了这个产品,等待另一个玩家加入并生成游戏,然后将该新玩家的 forcefield 给予他。”
通常情况下,
game.Players.PlayerAdded:connect(function(plr)用作获取 Player 对象的一种方法,但你已经通过调用 GetPlayerByUserId 获取了 Player 对象,因此可以直接使用它来获取角色模型。另外,一条无关的信息是,只有在成功赠送产品后才应将产品标记为 PurchaseGranted。通过将 PurchaseGranted 设置为默认返回状态,你可能会将未配置的产品销售给某个人,而你将没有任何回报就拿走他们的钱。
local PlayerService = game:GetService("Players") local Debris = game:GetService("Debris") mpService.ProcessReceipt = function(purchaceInfo) -- 确保玩家仍在游戏中 local plr = PlayerService:GetPlayerByUserId(purchaceInfo.PlayerId) if not plr then warn("Player could not be found. They might have left") return Enum.ProductPurchaseDecision.NotProcessedYet end if purchaceInfo.ProductId == xxxxxxx then -- 检查他们的角色是否已生成 local char = plr.Character if not char then warn("Could not find player's character in game") return Enum.ProductPurchaseDecision.NotProcessedYet end -- 赠送 force field local forceField = Instance.new("ForceField", char) -- 几秒钟后销毁 force field local duration = 30 Debris:AddItem(forceField, duration) -- 将此项目标记为授予的 return Enum.ProductPurchaseDecision.PurchaseGranted end -- 不知道他们买了什么 warn("Unprocessed item receipt", purchaseInfo) return Enum.ProductPurchaseDecision.NotProcessedYet end