scrobble.life
GAME DEV

ok so my first mission on my game

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)

Comments · 4

  • @web-gnar(72)· 332d

    share screen shots of Roblox editor when you learn new things, it would be cool to see how roblox editor compares to other game editors

  • @web-gnar(72)· 332d

    right on! nice first mission. i have no idea how roblox editor works but either you need to make the origin point of the lid towards the back, then it will rotate like a hinge. but you probably want the Lid and the Chest seperate objects? how did you make the chest?

  • @vaipraonde(69)· 335d

    congratulations, i will help you finding out how to add that hinge and make this chest open!

  • @hivebuzz(74)· 335d

    Congratulations @knight.gamer! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

    You received more than 100 upvotes.
    Your next target is to reach 200 upvotes.
    You distributed more than 10 upvotes.
    Your next target is to reach 50 upvotes.

    You can view your badges on your board and compare yourself to others in the Ranking If you no longer want to receive notifications, reply to this comment with the word STOP

    Check out our last posts:

    Be ready for the October edition of the Hive Power Up Month!
    Hive Power Up Day - October 1st 2025