我可以创建这个roblox游戏,但我不希望用户拥有相同项目的多个

发布于 2025-02-08 13:24:23 字数 655 浏览 3 评论 0原文

我正在为我的游戏创建一家商店,我不希望用户多次购买同一商品,当该物品没有配备时,我的脚本正常工作,但是当我可以购买另一个商品时。

这是我当前的脚本

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2025-02-15 13:24:23

您的代码缺少对播放器的持有物品的支票,该项目在其角色下。

更正:

local function buy (plr)
    local leaderstats = plr:FindFirstChild('leaderstats')
    if leaderstats then
        local coins = leaderstats:FindFirstChild('Murabux')
        if not plr:WaitForChild("Backpack"):FindFirstChild("Katana") and not plr.Character: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

Your code is lacking a check for the held item from the player, which is under their character.

Correction:

local function buy (plr)
    local leaderstats = plr:FindFirstChild('leaderstats')
    if leaderstats then
        local coins = leaderstats:FindFirstChild('Murabux')
        if not plr:WaitForChild("Backpack"):FindFirstChild("Katana") and not plr.Character: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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文