ok so my first mission on my game

@knight.gamer · 2025-09-30 01:28 · GAME DEV

so i wanted treasure chests in my game when you click it give coins to player.

tried makin the chest actually open but it was all wrong and looked bad

image.png

so i asked chatgpt for help and turns out i need a hinge to pivot the lid kinda complicated for now so i decided to go simple when you click, the chest disappears then after a few mins it respawns again

image.png

still basic, but works for now


local chest = script.Parent
local clickDetector = chest:FindFirstChildWhichIsA("ClickDetector")

local respawnTime = 600 -- 10 minutes in seconds

-- Function to give Gold
local function giveGold(player)
    -- Random Gold between 500 and 1000
    local goldReward = math.random(500, 1000)

    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local gold = leaderstats:FindFirstChild("Gold")

        -- If Gold doesn't exist, create it
        if not gold then
            gold = Instance.new("IntValue")
            gold.Name = "Gold"
            gold.Value = 0
            gold.Parent = leaderstats
        end

        gold.Value = gold.Value + goldReward
    end
end

-- Function when clicked
local function onChestClicked(player)
    -- Give Gold
    giveGold(player)

    -- Hide chest
    for _, part in pairs(chest:GetDescendants()) do
        if part:IsA("BasePart") then
            part.Transparency = 1
            part.CanCollide = false
        end
    end

    -- Wait for respawn time
    task.delay(respawnTime, function()
        -- Show chest again
        for _, part in pairs(chest:GetDescendants()) do
            if part:IsA("BasePart") then
                part.Transparency = 0
                part.CanCollide = true
            end
        end
    end)
end

-- Connect click event
clickDetector.MouseClick:Connect(onChestClicked)

#gamedev #roblox #games #dev #script #code #chest
Payout: 0.000 HBD
Votes: 14
More interactions (upvote, reblog, reply) coming soon.