local i=game:GetService("\080\108\097\121\101\114\115")local M=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local D=game:GetService("\087\111\114\107\115\112\097\099\101")local p=M:WaitForChild("\108\105\098")local x=M:WaitForChild("\099\111\109\109\111\110")local K=script.Parent.Parent local o=x:WaitForChild("\117\116\105\108")local j=require(p:WaitForChild("\082\069\067\083"))local w=require(x:WaitForChild("\082\101\099\115\067\111\109\112\111\110\101\110\116\115"))local R=require(o:WaitForChild("\104\105\116\073\115\089\111\117"))local U=j.System:extend("\067\111\105\110\083\121\115\116\101\109")local e=1453122289 function U.coinTouched(p,i,M,D)if R(D)then p.api:requestCoinCollect(i.spawnPart)M:Destroy()local D=p:getClientModule("\083\111\117\110\100")if D then local M=1+(math.random()*.2-.1)D:playSound(e,.5,M,i.spawnPart)end end end function U.addCoin(D,i,M)i.Touched:Connect(function(p)D:coinTouched(M,i,p)end)end function U.init(i)i.maid.componentAdded=(i.core:getComponentAddedSignal(w.Coin)):Connect(function(M,D)i:addCoin(M,D)end)for M,D in i.core:components(w.Coin)do i:addCoin(M,D)end end return U
-- increments the score of players that touch CoinTrigger instances, destroys those instances when touched.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local lib = ReplicatedStorage:WaitForChild("lib")
local common = ReplicatedStorage:WaitForChild("common")
local client = script.Parent.Parent
local util = common:WaitForChild("util")

local RECS = require(lib:WaitForChild("RECS"))
local Components = require(common:WaitForChild("RecsComponents"))

local hitIsYou = require(util:WaitForChild("hitIsYou"))

local CoinSystem = RECS.System:extend("CoinSystem")

local COIN_SOUND_ID = 1453122289

function CoinSystem:coinTouched(coin, instance, hit)
    if hitIsYou(hit) then
        self.api:requestCoinCollect(coin.spawnPart)
        instance:Destroy()

        local Sound = self:getClientModule("Sound")

        if Sound then
            local pitch = 1 + (math.random()*0.2 - 0.1)
            Sound:playSound(COIN_SOUND_ID,0.5,pitch,coin.spawnPart)
        end
    end
end

function CoinSystem:addCoin(instance,coin)
    instance.Touched:Connect(function(hit)
        self:coinTouched(coin, instance, hit)
    end)
end

function CoinSystem:init()

    self.maid.componentAdded =
        self.core:getComponentAddedSignal(Components.Coin):Connect(
            function(instance, coin)
                self:addCoin(instance,coin)
            end)

    for instance, coin in self.core:components(Components.Coin) do
        self:addCoin(instance,coin)
    end
end

return CoinSystem