在 Roblox 上制作经营游戏

我正在 Roblox 上制作一款经营游戏,但我的代码的一部分不起作用...这个问题在我游戏中的每个经营模式中都会出现(因为它们几乎共用相同的代码行)...当玩家使用游戏内现金购买武器面板时,他们应该在接触面板时将武器放入物品栏中...但是玩家似乎没有得到武器。这里是与武器面板相关的代码部分:

wep = script.Parent.WeaponName.Value
deb = true
giv = script.Parent.Giver
function touch(part)
    local hum = part.Parent:FindFirstChild("Humanoid")
    if hum then
        local plr = game.Players:FindFirstChild(part.Parent.Name)
        if plr then
            if deb == true then
                deb = false
                giv.BrickColor = BrickColor.new("Really red")
                local weapon = game.Lighting:FindFirstChild(wep)
                local w2 = weapon:Clone()
                w2.Parent = plr.Backpack
                wait(script.Parent.RegenTime.Value)
                giv.BrickColor = BrickColor.new("Bright violet")
                deb = true
            end
        end
    end
end
script.Parent.Giver.Touched:connect(touch)

请帮忙解决问题 :( 我无法理解这个 Giver 脚本的问题,也无法理解为什么它无法将特定武器交给玩家。

编程语言:Lua

点赞