local J={}local s=script.Parent.TeamColor.Value local p=require(script.Parent.Parent.Parent.Settings)local Z=script.Parent.CurrencyToCollect local d=game:GetService("\068\101\098\114\105\115")local t=p.StealSettings local F=true script.Parent.Essentials.Spawn.TeamColor=s script.Parent.Essentials.Spawn.BrickColor=s function Sound(J,s)if J:FindFirstChild("\083\111\117\110\100")then return else local p=Instance.new("\083\111\117\110\100",J)p.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..tostring(s)p:Play()delay(p.TimeLength,function()p:Destroy()end)end end for J,s in pairs(script.Parent.Essentials:GetChildren())do if s.Name=="\080\097\114\116\067\111\108\108\101\099\116\111\114"then s.Touched:connect(function(J)if J:FindFirstChild("\067\097\115\104")then Z.Value=Z.Value+J.Cash.Value d:AddItem(J,.1)end end)end end deb=false script.Parent.Essentials.Giver.Touched:connect(function(J)local s=game.Players:GetPlayerFromCharacter(J.Parent)if s~=nil then if script.Parent.Owner.Value==s then if J.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then if J.Parent.Humanoid.Health>0 then if deb==false then deb=true script.Parent.Essentials.Giver.BrickColor=BrickColor.new("\066\114\105\103\104\116 \114\101\100")local J=game.ServerStorage.PlayerMoney:FindFirstChild(s.Name)if J~=nil then Sound(script.Parent.Essentials,p.Sounds.Collect)J.Value=J.Value+Z.Value Z.Value=0 wait(1)script.Parent.Essentials.Giver.BrickColor=BrickColor.new("\083\101\097 \103\114\101\101\110")deb=false end end end end elseif t.Stealing then if F==true then F=false delay(t.PlayerProtection,function()F=true end)if J.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then if J.Parent.Humanoid.Health>0 then local J=game.ServerStorage.PlayerMoney:FindFirstChild(s.Name)if J~=nil then local s=math.floor(Z.Value*t.StealPrecent)Sound(script.Parent.Essentials,p.Sounds.Collect)J.Value=J.Value+s Z.Value=Z.Value-s end end end else Sound(script.Parent.Essentials,p.Sounds.Error)end end end end)script.Parent:WaitForChild("\066\117\116\116\111\110\115")for s,Z in pairs(script.Parent.Buttons:GetChildren())do spawn(function()if Z:FindFirstChild("\072\101\097\100")then local s=script.Parent.Purchases:WaitForChild(Z.Object.Value)if s~=nil then J[s.Name]=s:Clone()s:Destroy()else error("\079\098\106\101\099\116 \109\105\115\115\105\110\103 \102\111\114 \098\117\116\116\111\110\058 "..(Z.Name.."\044 \098\117\116\116\111\110 \104\097\115 \098\101\101\110 \114\101\109\111\118\101\100"))Z.Head.CanCollide=false Z.Head.Transparency=1 end if Z:FindFirstChild("\068\101\112\101\110\100\101\110\099\121")then Z.Head.CanCollide=false Z.Head.Transparency=1 coroutine.resume(coroutine.create(function()if script.Parent.PurchasedObjects:WaitForChild(Z.Dependency.Value)then if p.ButtonsFadeIn then for J=1,20,1 do wait(p.FadeInTime/20)Z.Head.Transparency=Z.Head.Transparency-.05 end end Z.Head.CanCollide=true Z.Head.Transparency=0 end end))end Z.Head.Touched:connect(function(J)local s=game.Players:GetPlayerFromCharacter(J.Parent)if Z.Head.CanCollide==true then if s~=nil then if script.Parent.Owner.Value==s then if J.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then if J.Parent.Humanoid.Health>0 then local J=game.ServerStorage.PlayerMoney:FindFirstChild(s.Name)if J~=nil then if Z:FindFirstChild("\071\097\109\101\112\097\115\115")and Z.Gamepass.Value>=1 then if(game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")):PlayerOwnsAsset(s,Z.Gamepass.Value)then Purchase({[1]=Z.Price.Value,[2]=Z;[3]=J})else(game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")):PromptPurchase(s,Z.Gamepass.Value)end elseif Z:FindFirstChild("\068\101\118\080\114\111\100\117\099\116")and Z.DevProduct.Value>=1 then(game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")):PromptProductPurchase(s,Z.DevProduct.Value)elseif J.Value>=Z.Price.Value then Purchase({[1]=Z.Price.Value;[2]=Z;[3]=J})Sound(Z,p.Sounds.Purchase)else Sound(Z,p.Sounds.ErrorBuy)end end end end end end end end)end end)end function Purchase(s)local Z=s[1]local d=s[2]local t=s[3]t.Value=t.Value-Z J[d.Object.Value].Parent=script.Parent.PurchasedObjects if p.ButtonsFadeOut then d.Head.CanCollide=false coroutine.resume(coroutine.create(function()for J=1,20,1 do wait(p.FadeOutTime/20)d.Head.Transparency=d.Head.Transparency+.05 end end))else d.Head.CanCollide=false d.Head.Transparency=1 end end function Create(J)local s=Instance.new("\077\111\100\101\108");(Instance.new("\078\117\109\098\101\114\086\097\108\117\101",s)).Value=J[1]s.Value.Name="\067\111\115\116";(Instance.new("\079\098\106\101\099\116\086\097\108\117\101",s)).Value=J[2]s.Value.Name="\066\117\116\116\111\110"local p=Instance.new("\079\098\106\101\099\116\086\097\108\117\101",s)p.Name="\083\116\097\116\115"p.Value=J[3]s.Parent=script.Parent.BuyObject end;(script.Parent:WaitForChild("\066\117\121\079\098\106\101\099\116")).ChildAdded:connect(function(J)local s={}s[1]=J.Cost.Value s[2]=J.Button.Value s[3]=J.Stats.Value Purchase(s)wait(10)J:Destroy()end)
	--[[
		All configurations are located in the "Settings" Module script.
		Please don't edit this script unless you know what you're doing.
	--]]
	local Objects = {}
	local TeamColor = script.Parent.TeamColor.Value
	local Settings = require(script.Parent.Parent.Parent.Settings)
	local Money = script.Parent.CurrencyToCollect
	local Debris = game:GetService('Debris')
	local Stealing = Settings.StealSettings
	local CanSteal = true -- don't change or else you won't be able to steal currency
	
	script.Parent.Essentials.Spawn.TeamColor = TeamColor
	script.Parent.Essentials.Spawn.BrickColor = TeamColor
	
	function Sound(part,id)
		if part:FindFirstChild('Sound') then
			return
		else
			local Sound = Instance.new('Sound',part)
			Sound.SoundId = "rbxassetid://"..tostring(id)
			Sound:Play()
			delay(Sound.TimeLength, function()
				Sound:Destroy()
			end)
		end
	end
	
	--Parts that fall into the collector(s) get processed
	for i,v in pairs(script.Parent.Essentials:GetChildren()) do
		if v.Name == "PartCollector" then
			v.Touched:connect(function(Part)
				if Part:FindFirstChild('Cash') then
					Money.Value = Money.Value + Part.Cash.Value
					Debris:AddItem(Part,0.1)
				end
			end)
		end
	end
	
	--Player Touched Collector processor
	deb = false
	script.Parent.Essentials.Giver.Touched:connect(function(hit)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player ~= nil then
			if script.Parent.Owner.Value == player then
				if hit.Parent:FindFirstChild("Humanoid") then
					if hit.Parent.Humanoid.Health > 0 then
						if deb == false then
							deb = true
							script.Parent.Essentials.Giver.BrickColor = BrickColor.new("Bright red")
							local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if Stats ~= nil then 
							Sound(script.Parent.Essentials, Settings.Sounds.Collect)
							Stats.Value = Stats.Value + Money.Value
							Money.Value = 0
							wait(1)
							script.Parent.Essentials.Giver.BrickColor = BrickColor.new("Sea green")
							deb = false
							end
						end
					end
				end
			elseif Stealing.Stealing then -- if player isn't owner and stealing is on
				if CanSteal == true then
					CanSteal = false
					delay(Stealing.PlayerProtection, function()
						CanSteal = true
					end)
					if hit.Parent:FindFirstChild("Humanoid") then
						if hit.Parent.Humanoid.Health > 0 then
							local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
							if Stats ~= nil then
								local Difference = math.floor(Money.Value * Stealing.StealPrecent)
								Sound(script.Parent.Essentials, Settings.Sounds.Collect)
								Stats.Value = Stats.Value + Difference
								Money.Value = Money.Value - Difference
							end
						end
					end
				else
					Sound(script.Parent.Essentials, Settings.Sounds.Error)
				end
			end
		end
	end)
	
	script.Parent:WaitForChild("Buttons")
	for i,v in pairs(script.Parent.Buttons:GetChildren()) do
		spawn(function()
		if v:FindFirstChild("Head") then
			
			local ThingMade = script.Parent.Purchases:WaitForChild(v.Object.Value)
			if ThingMade ~= nil then
				Objects[ThingMade.Name] = ThingMade:Clone()
				ThingMade:Destroy()
			else
				--//Button doesn't have object, remove it
				error('Object missing for button: '..v.Name..', button has been removed')
				v.Head.CanCollide = false
				v.Head.Transparency = 1
			end
									
			if v:FindFirstChild("Dependency") then --// if button needs something unlocked before it pops up
				v.Head.CanCollide = false
				v.Head.Transparency = 1
				coroutine.resume(coroutine.create(function()
					if script.Parent.PurchasedObjects:WaitForChild(v.Dependency.Value) then
						if Settings['ButtonsFadeIn'] then
							for i=1,20 do
								wait(Settings['FadeInTime']/20)
								v.Head.Transparency = v.Head.Transparency - 0.05
							end
						end
						v.Head.CanCollide = true
						v.Head.Transparency = 0
					end
				end))
			end
			
			v.Head.Touched:connect(function(hit)
				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if v.Head.CanCollide == true then
					if player ~= nil then
						if script.Parent.Owner.Value == player then
							if hit.Parent:FindFirstChild("Humanoid") then
								if hit.Parent.Humanoid.Health > 0 then
									local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
									if PlayerStats ~= nil then
										if (v:FindFirstChild('Gamepass')) and (v.Gamepass.Value >= 1) then
											if game:GetService("MarketplaceService"):PlayerOwnsAsset(player,v.Gamepass.Value) then
												Purchase({[1] = v.Price.Value,[2] = v,[3] = PlayerStats})
											else
												game:GetService('MarketplaceService'):PromptPurchase(player,v.Gamepass.Value)
											end
										elseif (v:FindFirstChild('DevProduct')) and (v.DevProduct.Value >= 1) then
											game:GetService('MarketplaceService'):PromptProductPurchase(player,v.DevProduct.Value)
										elseif PlayerStats.Value >= v.Price.Value then
											Purchase({[1] = v.Price.Value,[2] = v,[3] = PlayerStats})
											Sound(v, Settings.Sounds.Purchase)
										else
											Sound(v, Settings.Sounds.ErrorBuy)
										end
									end
								end
							end
						end
					end
				end
			end)
			end
		end)
	end
	
	function Purchase(tbl)
		local cost = tbl[1]
		local item = tbl[2]
		local stats = tbl[3]
		stats.Value = stats.Value - cost
		Objects[item.Object.Value].Parent = script.Parent.PurchasedObjects
		if Settings['ButtonsFadeOut'] then
			item.Head.CanCollide = false
			coroutine.resume(coroutine.create(function()
				for i=1,20 do
					wait(Settings['FadeOutTime']/20)
					item.Head.Transparency = item.Head.Transparency + 0.05
				end
			end))
		else
			item.Head.CanCollide = false
			item.Head.Transparency = 1
		end
	end
	
	function Create(tab)
		local x = Instance.new('Model')
		Instance.new('NumberValue',x).Value = tab[1]
		x.Value.Name = "Cost"
		Instance.new('ObjectValue',x).Value = tab[2]
		x.Value.Name = "Button"
		local Obj = Instance.new('ObjectValue',x)
		Obj.Name = "Stats"
		Obj.Value = tab[3]
		x.Parent = script.Parent.BuyObject
	end
	
	--// This was very rushed and is inefficent; if you plan on making something like this don't use a child added listener.
	script.Parent:WaitForChild('BuyObject').ChildAdded:connect(function(child)
		local tab = {}
		tab[1] = child.Cost.Value
		tab[2] = child.Button.Value
		tab[3] = child.Stats.Value
		Purchase(tab)
		wait(10)
		child:Destroy()
	end)