So I made a LocalScript that controls the in-game Shop GUI.

Full code is below.

  • MiddleMan is a RemoteFunction in ReplicatedStorage
  • CSB is a RemoteEvent in ReplicatedStorage

TREE: http://prntscr.com/anarid

OUTPUT: http://prntscr.com/anaooa

CODE:

--[[
	ITEM TYPES:
	0 - Game Pass
	1 - Coins Purchase
	2 - XP Purchase
	3 - Free Item
	4 - Not available
	5 - T-Shirt
	6 - Developer Product
--]]
local ItemTypes={}
ItemTypes.GamePass = 0
ItemTypes.CoinsPurchase = 1
ItemTypes.XPPurchase = 2
ItemTypes.FreeItem = 3
ItemTypes.NotAvailable = 4
ItemTypes.TShirt = 5
ItemTypes.DeveloperProduct = 6

local CSB = game:GetService('ReplicatedStorage'):WaitForChild('CSB')
local MiddleMan = game:GetService('ReplicatedStorage'):WaitForChild('MiddleMan')
local Player = game:GetService('Players').LocalPlayer

local Hidden = true
local Operating = false
local selectingPage = false
local working={}

local MainFrame = script.Parent:WaitForChild('MainFrame')
local Cancel = MainFrame:WaitForChild('Cancel')
local HiddenFrame = script.Parent:WaitForChild('HiddenFrame')
local Show = HiddenFrame:WaitForChild('Show')
local Pages = MainFrame:WaitForChild('Pages')
local PageSelector = MainFrame:WaitForChild('PageSelector')
local Page1But = PageSelector:WaitForChild('SelectPage1')
local Page2But = PageSelector:WaitForChild('SelectPage2')
local Page3But = PageSelector:WaitForChild('SelectPage3')

local DoShow
local DoHide
local DoUpdate
local SelectPage

local pn = 0
local pcall = function(f,dnw)
	pn=pn+1
	local s,e = xpcall(f,function(e)return e end)
	if (not s) and (not dnw) then warn('[LocalShopError #' .. tostring(pn) .. ']:',e) end
	return s,e
end

local function dp(x) if false then print('[LocalShopDebug]:',x) end end

local function C3(r,g,b)
	return Color3.new(r/255,g/255,b/255)
end

local PurchasesCache = {}

local BuyButtonConnections = {}

function CheckPurchased(itemKey)
	
	if PurchasesCache[itemKey] then print'1' return true end
	
	local RequestSuccess, Response = pcall(function()
		return MiddleMan:InvokeServer('CheckPurchased',itemKey)
	end)
	print(RequestSuccess,Response)
	if not RequestSuccess then Response = false end
	if type(Response)~='boolean' then Response = false end
	
	if Response then PurchasesCache[itemKey]=true return true end
	
	local RequestSuccess, Response = pcall(function()
		return MiddleMan:InvokeServer('CheckOwnership',itemKey)
	end)
	if not RequestSuccess then Response = false end
	if type(Response)~='boolean' then Response = false end
	
	if Response then PurchasesCache[itemKey]=true end
	
	return Response
end

function DoShow()
	DoUpdate()
	pcall(function() MainFrame:TweenPosition(UDim2.new(0.4,0,0.15,0)) end)
	pcall(function() HiddenFrame:TweenPosition(UDim2.new(-0.1,0,0.35,0)) end)
end
function DoHide()
	pcall(function() MainFrame:TweenPosition(UDim2.new(-1,0,0.15,0)) end)
	pcall(function() HiddenFrame:TweenPosition(UDim2.new(0,0,0.35,0)) end)
end
function DoUpdate()
	pcall(function()
		local function UpdateItem(pageNum,name)
			local page = Pages:FindFirstChild('Page'..tostring(pageNum))
			if not page then return false end
			local item = page:FindFirstChild(name,true)
			if not item then return false end
			
			local itemType = item:FindFirstChild('ItemType')
			if not itemType then return false end
			itemType = itemType.Value
			
			local itemPrice = item:FindFirstChild('ItemPrice')
			if not itemPrice then return false end
			itemPrice = itemPrice.Value
			
			local itemKey = item:FindFirstChild('ItemKey')
			if not itemKey then return false end
			itemKey = itemKey.Value
			
			local BuyButton = item:FindFirstChild('BuyButton')
			if not BuyButton then return false end
			
			if CheckPurchased(itemKey) then
				pcall(function() item.ItemType.Value = ItemTypes.NotAvailable end)
				BuyButton.BackgroundColor3 = C3(20,20,20)
				BuyButton.TextColor3 = C3(255,255,255)
				BuyButton.Text = "OWNED"
			end
			
			if BuyButtonConnections[itemKey] then
				pcall(function() BuyButtonConnections[itemKey]:disconnect() end)
			end
			
			BuyButtonConnections[itemKey] = BuyButton.MouseButton1Click:connect(function()
				if BuyButton.Text == "OWNED" then return end
				if itemType==ItemTypes.GamePass then
					if CheckPurchased(itemKey) then
						pcall(function() item.ItemType.Value = ItemTypes.NotAvailable end)
						BuyButton.BackgroundColor3 = C3(20,20,20)
						BuyButton.TextColor3 = C3(255,255,255)
						BuyButton.Text = "OWNED"
					else
						game:GetService('MarketplaceService'):PromptPurchase(Player,itemKey)
					end
				elseif itemType==ItemTypes.CoinsPurchase then
					
				elseif itemType==ItemTypes.XPPurchase then
					
				elseif itemType==ItemTypes.FreeItem then
					
				elseif itemType==ItemTypes.NotAvailable then
					return
				elseif itemType==ItemTypes.TShirt then
					
				elseif itemType==ItemTypes.DeveloperProduct then
					game:GetService('MarketplaceService'):PromptProductPurchase(Player,itemKey)
				else
					return
				end
				
			end)
		end
		
		pcall(function() UpdateItem(1,'Item1') end)
		pcall(function() UpdateItem(1,'Item2') end)
		pcall(function() UpdateItem(1,'Item3') end)
		
		pcall(function() UpdateItem(2,'Item1') end)
		pcall(function() UpdateItem(2,'Item2') end)
		pcall(function() UpdateItem(2,'Item3') end)
		
		pcall(function() UpdateItem(3,'Item1') end)
		pcall(function() UpdateItem(3,'Item2') end)
		pcall(function() UpdateItem(3,'Item3') end)
	end)
end

function SelectPage(pageNum)
	if selectingPage then return end
	local page = Pages:FindFirstChild('Page'..tostring(pageNum))
	if not page then return end
	if page.Visible then return end
	if selectingPage then return end
	selectingPage=true
	
	for i,v in pairs(Pages:children()) do
		pcall(function() v.Visible=false end)
	end
	
	pcall(function() page.Visible=true end)
	
	for i,v in pairs(PageSelector:children()) do
		pcall(function() v.BackgroundColor3 = C3(100,100,100) end)
	end
	
	pcall(function() PageSelector:FindFirstChild('SelectPage'..tostring(pageNum)).BackgroundColor3=C3(60,60,60) end)
	
	delay(.5,function() selectingPage=false end)
end

--DoHide()

Show.MouseButton1Down:connect(function()
	if Hidden and not Operating then
		Operating = true
		DoShow()
		Hidden = false
		delay(1,function() Operating = false end)
	end
end)

Cancel.MouseButton1Down:connect(function()
	if not Hidden and not Operating then
		Operating = true
		DoHide()
		Hidden = true
		delay(1,function() Operating = false end)
	end
end)

Page1But.MouseButton1Click:connect(function() SelectPage(1) end)
Page2But.MouseButton1Click:connect(function() SelectPage(2) end)
Page3But.MouseButton1Click:connect(function() SelectPage(3) end)


2 comments

0

Dude... You're telling me you have No Clue where the error could be? Also, how did you write all of this without debugging parts of it as you were going?

0

@wfvj014 I have no idea where it is, and the code works fine for most of it, I just noticed that.