local coinPart = script.Parent
local debounce = false

coinPart.Touched:Connect(function(hit)
	if not debounce then
		local character = hit.Parent
		local humanoid = character:FindFirstChild("Humanoid")

		-- 1. Check if a real player touched it
		if humanoid then
			local player = game.Players:GetPlayerFromCharacter(character)

			if player then
				debounce = true

				-- 2. Add to the Coin Value in PlayerStats
				local playerStats = player:WaitForChild("PlayerStats")
				local playerCoins = playerStats:WaitForChild("Coins")
				playerCoins.Value = playerCoins.Value + 1 -- Adds 1 coin!

				-- 3. Play the collection sound safely
				if coinPart:FindFirstChild("Sound") then
					local sound = coinPart.Sound:Clone()
					sound.Parent = player:WaitForChild("PlayerGui")
					sound:Play()
					-- Clean up the cloned sound from PlayerGui after it finishes playing
					game:GetService("Debris"):AddItem(sound, 3) 
				end

				-- 4. Make the coin disappear immediately
				coinPart.Transparency = 1
				coinPart.CanCollide = false

				-- 5. Wait 10 seconds before letting it respawn
				task.wait(10)

				-- 6. Bring the coin back and reset the debounce
				coinPart.Transparency = 0
				coinPart.CanCollide = true
				debounce = false
			end
		end
	end
end)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: