Gamepasses fail to load on surface gui

Im trying to make a donating game and i cant find the issue in my scripts but the gamepasses so not show for some reason.

I’m probably not going to get a lot of help because there are a lot of lines of code

This is the first script located in ServerScriptService (Normal Script)

local module = require(script.Parent.MainModule)

local textService = game:GetService("TextService")
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local donationStore = dss:GetDataStore("MainStore")
local http = game:GetService("HttpService")
local joinedroation = game.ReplicatedStorage.Events.JoinedRotation

local function claimBoothRandomly(player)
    local unclaimedBooths = {}

    for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
        if not stand.Claimed.Value then
            table.insert(unclaimedBooths, stand)
        end
    end

	if #unclaimedBooths > 0 then
		local randomBooth = unclaimedBooths[math.random(1, #unclaimedBooths)]

		randomBooth.Claimed.Value = true
		randomBooth.ClaimedUserName.Value = player.Name

        randomBooth.Base.Unclaimed.Enabled = false
        randomBooth.Base.ClaimedInfoDisplay.UserName.Text = player.Name
        randomBooth.Base.ClaimedInfoDisplay.Enabled = true

        -- Teleport the player's HumanoidRootPart to TPpart inside the booth (for R15 characters)
        local TPpart = randomBooth:FindFirstChild("TPpart")
        if TPpart and TPpart:IsA("Part") then
            local character = player.Character
            if character then
                local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
                if humanoidRootPart and humanoidRootPart:IsA("Part") then
                    humanoidRootPart.CFrame = TPpart.CFrame

                    -- Set the player's WalkSpeed and JumpHeight to 0
                    local humanoid = character:FindFirstChildOfClass("Humanoid")
                    if humanoid then
                        humanoid.WalkSpeed = 0
                        humanoid.JumpPower = 0
                    end
                end
            end
        end
    else
        print("All booths are claimed.")
    end
end

joinedroation.OnServerEvent:Connect(claimBoothRandomly)

game.ReplicatedStorage.Events.EditStand.OnServerEvent:Connect(function(plr,text)
	local filtered = textService:FilterStringAsync(text,plr.UserId):GetNonChatStringForBroadcastAsync()
	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		if stand.Claimed.Value == true and stand.ClaimedUserName.Value == plr.Name then
			stand.MessagePart.SurfaceGui.UserMessage.Text = filtered
		end 
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"

	local donated = Instance.new("IntValue",leaderstats)
	donated.Name = "Donated"

	local received = Instance.new("IntValue",leaderstats)
	received.Name = "Received"

	local data

	local success, errormsg = pcall(function()
		data = donationStore:GetAsync(plr.UserId)
	end)

	if success then
		if data then
			data = http:JSONDecode(data)
			donated.Value = data[1]
			received.Value = data[2]
		else
			print("No previous data.")
		end
	else
		warn(errormsg)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local data = {plr.leaderstats.Donated.Value,plr.leaderstats.Received.Value}

	local success, errormsg = pcall(function()
		data = http:JSONEncode(data)
		donationStore:SetAsync(plr.UserId,data)
	end)

	if success then
		print("Successfully saved.")
	else
		warn(errormsg)
	end

	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		if stand.ClaimedUserName.Value == plr.Name then
			module.clearStand(stand)
		end
	end
end)

mps.PromptGamePassPurchaseFinished:Connect(function(plr, passId, purchased)
	if purchased == true then
		print("Purchased.")

		local item = module.findItem(passId)

		local cost = item.Cost.Value
		local plrBy = game.Players:FindFirstChild(item.Parent.Parent.Parent.Parent.ClaimedUserName.Value)

		if cost then
			print(cost)
			plr.leaderstats.Donated.Value += cost
		else
			print("Could not find cost.")
		end

		if plrBy then
			plrBy.leaderstats.Received.Value += cost -- Corrected name to "Received"
		else
			print("Could not find PlrBy.")
		end

		module.updateStandsEarned()
	else
		print("Not purchased.")
	end
end)

mps.PromptPurchaseFinished:Connect(function(plr, assetId, purchased)
	if purchased == true then
		print("Purchased.")

		local item = module.findItem(assetId)

		local cost = item.Cost.Value
		local plrBy = game.Players:FindFirstChild(item.Parent.Parent.Parent.Parent.ClaimedUserName.Value)

		if cost then
			print(cost)
			plr.leaderstats.Donated.Value += cost
		else
			print("Could not find cost.")
		end

		if plrBy then
			plrBy.leaderstats.Received.Value += cost -- Corrected name to "Received"
		else
			print("Could not find PlrBy.")
		end

		module.updateStandsEarned()
	end
end)

and this is the second script also in ServerScriptService (Module Script)

local module = require(script.Parent.MainModule)

local textService = game:GetService("TextService")
local mps = game:GetService("MarketplaceService")
local dss = game:GetService("DataStoreService")
local donationStore = dss:GetDataStore("MainStore")
local http = game:GetService("HttpService")
local joinedroation = game.ReplicatedStorage.Events.JoinedRotation

local function claimBoothRandomly(player)
    local unclaimedBooths = {}

    for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
        if not stand.Claimed.Value then
            table.insert(unclaimedBooths, stand)
        end
    end

	if #unclaimedBooths > 0 then
		local randomBooth = unclaimedBooths[math.random(1, #unclaimedBooths)]

		randomBooth.Claimed.Value = true
		randomBooth.ClaimedUserName.Value = player.Name

        randomBooth.Base.Unclaimed.Enabled = false
        randomBooth.Base.ClaimedInfoDisplay.UserName.Text = player.Name
        randomBooth.Base.ClaimedInfoDisplay.Enabled = true

        -- Teleport the player's HumanoidRootPart to TPpart inside the booth (for R15 characters)
        local TPpart = randomBooth:FindFirstChild("TPpart")
        if TPpart and TPpart:IsA("Part") then
            local character = player.Character
            if character then
                local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
                if humanoidRootPart and humanoidRootPart:IsA("Part") then
                    humanoidRootPart.CFrame = TPpart.CFrame

                    -- Set the player's WalkSpeed and JumpHeight to 0
                    local humanoid = character:FindFirstChildOfClass("Humanoid")
                    if humanoid then
                        humanoid.WalkSpeed = 0
                        humanoid.JumpPower = 0
                    end
                end
            end
        end
    else
        print("All booths are claimed.")
    end
end

joinedroation.OnServerEvent:Connect(claimBoothRandomly)

game.ReplicatedStorage.Events.EditStand.OnServerEvent:Connect(function(plr,text)
	local filtered = textService:FilterStringAsync(text,plr.UserId):GetNonChatStringForBroadcastAsync()
	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		if stand.Claimed.Value == true and stand.ClaimedUserName.Value == plr.Name then
			stand.MessagePart.SurfaceGui.UserMessage.Text = filtered
		end 
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"

	local donated = Instance.new("IntValue",leaderstats)
	donated.Name = "Donated"

	local received = Instance.new("IntValue",leaderstats)
	received.Name = "Received"

	local data

	local success, errormsg = pcall(function()
		data = donationStore:GetAsync(plr.UserId)
	end)

	if success then
		if data then
			data = http:JSONDecode(data)
			donated.Value = data[1]
			received.Value = data[2]
		else
			print("No previous data.")
		end
	else
		warn(errormsg)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local data = {plr.leaderstats.Donated.Value,plr.leaderstats.Received.Value}

	local success, errormsg = pcall(function()
		data = http:JSONEncode(data)
		donationStore:SetAsync(plr.UserId,data)
	end)

	if success then
		print("Successfully saved.")
	else
		warn(errormsg)
	end

	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		if stand.ClaimedUserName.Value == plr.Name then
			module.clearStand(stand)
		end
	end
end)

mps.PromptGamePassPurchaseFinished:Connect(function(plr, passId, purchased)
	if purchased == true then
		print("Purchased.")

		local item = module.findItem(passId)

		local cost = item.Cost.Value
		local plrBy = game.Players:FindFirstChild(item.Parent.Parent.Parent.Parent.ClaimedUserName.Value)

		if cost then
			print(cost)
			plr.leaderstats.Donated.Value += cost
		else
			print("Could not find cost.")
		end

		if plrBy then
			plrBy.leaderstats.Received.Value += cost -- Corrected name to "Received"
		else
			print("Could not find PlrBy.")
		end

		module.updateStandsEarned()
	else
		print("Not purchased.")
	end
end)

mps.PromptPurchaseFinished:Connect(function(plr, assetId, purchased)
	if purchased == true then
		print("Purchased.")

		local item = module.findItem(assetId)

		local cost = item.Cost.Value
		local plrBy = game.Players:FindFirstChild(item.Parent.Parent.Parent.Parent.ClaimedUserName.Value)

		if cost then
			print(cost)
			plr.leaderstats.Donated.Value += cost
		else
			print("Could not find cost.")
		end

		if plrBy then
			plrBy.leaderstats.Received.Value += cost -- Corrected name to "Received"
		else
			print("Could not find PlrBy.")
		end

		module.updateStandsEarned()
	end
end)

this is the 3rd script located in starterplayerscripts (local scripts)

local mps = game:GetService("MarketplaceService")

while wait(1) do
	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		for _, frame in pairs(stand:WaitForChild("Products").Items.ScrollingFrame:GetChildren()) do
			if frame:IsA("Frame") then
				frame.RobuxCost.MouseButton1Click:Connect(function()
					if frame.ItemTypeId.Value == 34 then
						mps:PromptGamePassPurchase(game.Players.LocalPlayer, frame.ItemID.Value)
					else
						mps:PromptPurchase(game.Players.LocalPlayer, frame.ItemID.Value)
					end
				end)
			end
		end

		if stand.Claimed.Value == true then
			if stand.ClaimedUserName.Value == game.Players.LocalPlayer.Name then
				-- Update the raised amount in ClaimedInfoDisplay
				local plrBy = game.Players:FindFirstChild(stand.ClaimedUserName.Value)
				if plrBy then
					stand.Base.ClaimedInfoDisplay.UserRaised.Text = "R$" .. tostring(plrBy.leaderstats.Received.Value) .. " Raised"
				else
					print("Could not find player: " .. stand.ClaimedUserName.Value)
				end
			end
		end
	end
end

This shows the location of all the items in the stands
image

1 Like

That is true. Can you attempt to narrow down the code to a problematic section? Is it a server or client error? Which script manages them?

1 Like

Yes i can do that

MainModule (ModuleScript) Parent = ServerScriptService:

local module = {}

-- services
local dss = game:GetService("DataStoreService")
local http = game:GetService("HttpService")
local mps = game:GetService("MarketplaceService")

-- stores
local mainStore = dss:GetDataStore("MainDataStore")

-- variables
module.assetTypeIds = {
	["T-Shirt"] = 2,
	["Shirt"] = 11,
	["Pants"] = 12,
	["Pass"] = 34,
}
-- main functions

module.getItems = function(assetId, plrId)
	local allItems = {}

	local success, errormsg = pcall(function()
		local done = false
		local nextPageCursor

		while not done do
			local data

			if nextPageCursor then
				data = http:GetAsync("https://www.roproxy.com/users/inventory/list-json?assetTypeId="..tostring(assetId).."&cursor="..nextPageCursor.."&itemsPerPage=100&userId="..tostring(plrId))
			else
				data = http:GetAsync("https://www.roproxy.com/users/inventory/list-json?assetTypeId="..tostring(assetId).."&cursor=&itemsPerPage=100&userId="..tostring(plrId))
			end

			if data then
				data = http:JSONDecode(data)
				local items = data["Data"]["Items"]

				for _, item in pairs(items) do
					table.insert(allItems, item)
				end

				if data["Data"]["nextPageCursor"] then
					nextPageCursor = data["Data"]["nextPageCursor"]
				else
					done = true
				end
			else
				warn("No data.")
			end
		end
	end)

	if success then
		print("Successfully retrieved data.")
	else
		warn(errormsg)
	end

	local createdByUser = {}

	print(allItems)

	for i, item in pairs(allItems) do
		pcall(function()
			if (item["Creator"]["Id"] == plrId) and (item["Product"]["IsForSale"] == true) then
				table.insert(createdByUser,item)
			end
		end)
	end

	print(tostring(#createdByUser).." items remain.")

	print(createdByUser)

	for _, item in pairs(createdByUser) do
		print(item["Item"]["Name"],"-",item["Product"]["PriceInRobux"])
	end

	return createdByUser
end

module.loadItems = function(stand, plr)
	for _, frame in pairs(stand.Products.Items.ScrollingFrame:GetChildren()) do
		if frame:IsA("Frame") then
			frame:Destroy()
		end
	end

	local tshirts = module.getItems(module.assetTypeIds["T-Shirt"], plr.UserId)
	local passes = module.getItems(module.assetTypeIds["Pass"], plr.UserId)
	local shirts = module.getItems(module.assetTypeIds["Shirt"], plr.UserId)
	local pants = module.getItems(module.assetTypeIds["Pants"], plr.UserId)

	print(#tshirts, "T-Shirts found.")
	print(#shirts, "Shirts found.")
	print(#pants, "Pants found.")
	print(#passes, "Passes found.")

	local allItems = {}
	local tble = { tshirts, passes, shirts, pants }

	for _, itemType in pairs(tble) do
		for _, item in pairs(itemType) do
			table.insert(allItems, item)
		end
	end

--Rest of existing code--

	table.sort(allItems, function(a, b)
		return a["Product"]["PriceInRobux"] < b["Product"]["PriceInRobux"]
	end)

	for _, item in pairs(allItems) do
		local frame = script.Template:Clone()
		frame.ItemID.Value = item["Item"]["AssetId"]
		frame.Cost.Value = item["Product"]["PriceInRobux"]
		frame.ItemTypeId.Value = item["Item"]["AssetType"]
		frame.RobuxCost.Text = "$" .. tostring(item["Product"]["PriceInRobux"])
		frame.Parent = stand.Products.Items.ScrollingFrame
	end
end

Client Handle (Local Script) Parent = StarterPlayerScripts:

while wait(1) do
	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		for _, frame in pairs(stand:WaitForChild("Products").Items.ScrollingFrame:GetChildren()) do
			if frame:IsA("Frame") then
				frame.RobuxCost.MouseButton1Click:Connect(function()
					if frame.ItemTypeId.Value == 34 then
						mps:PromptGamePassPurchase(game.Players.LocalPlayer, frame.ItemID.Value)
					else
						mps:PromptPurchase(game.Players.LocalPlayer, frame.ItemID.Value)
					end
				end)
			end
		end

I don’t think the error is in the script named MainScript so i didn’t include it

1 Like

So, the items just don’t load? Try putting a print statement to show where the error is.

1 Like