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

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

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)