Код IT
← Каталог

Практикум — обби на Roblox — Монеты и защита от повторного сбора

Фрагмент из «Практикум — обби на Roblox»: Монеты и защита от повторного сбора.

lua spinoffencyclopedia9-04-razrabotka-igr-204 embed URL статья в энциклопедии
Lua main.lua
--!strict
-- В обработчике монеты (сервер)

local function grantCoinOnce(player: Player, coinId: string, amount: number)
    local tags = player:FindFirstChild("CoinTags") :: Folder?
    if not tags then
        tags = Instance.new("Folder")
        tags.Name = "CoinTags"
        tags.Parent = player
    end
    if tags:FindFirstChild(coinId) then
        return
    end
    local tag = Instance.new("BoolValue")
    tag.Name = coinId
    tag.Parent = tags

    DataModule.increment(player, "Coins", amount)
    local ls = player:FindFirstChild("leaderstats")
    local coins = ls and ls:FindFirstChild("Coins") :: IntValue?
    if coins then
        coins.Value = DataModule.get(player).Coins
    end
end
--!strict
-- В обработчике монеты (сервер)

local function grantCoinOnce(player: Player, coinId: string, amount: number)
    local tags = player:FindFirstChild("CoinTags") :: Folder?
    if not tags then
        tags = Instance.new("Folder")
        tags.Name = "CoinTags"
        tags.Parent = player
    end
    if tags:FindFirstChild(coinId) then
        return
    end
    local tag = Instance.new("BoolValue")
    tag.Name = coinId
    tag.Parent = tags

    DataModule.increment(player, "Coins", amount)
    local ls = player:FindFirstChild("leaderstats")
    local coins = ls and ls:FindFirstChild("Coins") :: IntValue?
    if coins then
        coins.Value = DataModule.get(player).Coins
    end
end