我可以创建这个roblox游戏,但我不希望用户拥有相同项目的多个
我正在为我的游戏创建一家商店,我不希望用户多次购买同一商品,当该物品没有配备时,我的脚本正常工作,但是当我可以购买另一个商品时。
这是我当前的脚本
local function buy (plr)
local leaderstats = plr:FindFirstChild('leaderstats')
if leaderstats then
local coins = leaderstats:FindFirstChild('Murabux')
if not plr:WaitForChild("Backpack"):FindFirstChild("Katana") then
if coins and coins.Value >= 90 then
coins.Value = coins.Value - 90
local clone = game:GetService('ReplicatedStorage').Katana:Clone()
clone.Parent = plr.Backpack
end
end
end
end
I'm creating a shop for my game and I don't want the user to be able to buy the same item multiple times my script works fine when the item isn't equipped but when it is I'm able to buy another one.
This is my current script
local function buy (plr)
local leaderstats = plr:FindFirstChild('leaderstats')
if leaderstats then
local coins = leaderstats:FindFirstChild('Murabux')
if not plr:WaitForChild("Backpack"):FindFirstChild("Katana") then
if coins and coins.Value >= 90 then
coins.Value = coins.Value - 90
local clone = game:GetService('ReplicatedStorage').Katana:Clone()
clone.Parent = plr.Backpack
end
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码缺少对播放器的持有物品的支票,该项目在其角色下。
更正:
Your code is lacking a check for the held item from the player, which is under their character.
Correction: