HTTPService code doesn't work

Hello, I’ve been working on a project one day and my script fails out of nowhere. No errors, warnings, etc.

Part of the script suspected to be not working:

game.ReplicatedStorage.GetPayouts.OnServerEvent:Connect(function(plr)
	local HttpService = game:GetService("HttpService")
	local err = plr.PlayerGui.GameUI.GetPayoutsFrame.Error
	local gamePassId = plr.PlayerGui.GameUI.GetPayoutsFrame.GamepassId.Text

	-- Fetch the game pass details from the API
	local detailsundecoded = HttpService:GetAsync("https://wave-graceful-hyacinth.glitch.me/?link=https://apis.roblox.com/game-passes/v1/game-passes/" .. gamePassId .. "/product-info")

	-- Check if the game pass was not found
	if detailsundecoded == '"gamepass not found"' then
		err.Text = "Gamepass not found."
		return
	end

	-- Attempt to decode the JSON response
	local success, details = pcall(function()
		return HttpService:JSONDecode(detailsundecoded)
	end)

	if not success then
		err.Text = "Failed to decode JSON data."
		return
	end

	-- Debugging: Print details to the output for inspection
	print("Decoded JSON Details: ", details)

	-- Validate the Creator field
	if not details["Creator"] then
		err.Text = "Creator field is missing in gamepass details."
		return
	end

	local creatorName = details["Creator"]["Name"]

	if not creatorName then
		err.Text = "Creator Name is missing in gamepass details."
		return
	end

	-- Check if the Creator's Name matches the player's Name
	if creatorName == plr.Name then
		local priceInRobux = details["PriceInRobux"]
		local userRobux = playersrobux[plr.Name] or 0

		-- Ensure the player has enough Robux
		if priceInRobux <= userRobux then
			-- Check if the price is one of the allowed values
			local validPrices = {5, 10, 25, 50, 100, 500, 1000}
			local isValidPrice = false

			for _, validPrice in ipairs(validPrices) do
				if priceInRobux == validPrice then
					isValidPrice = true
					break
				end
			end

			if isValidPrice then
				table.insert(gamepassqueue, gamePassId)
				playersrobux[plr.Name] = userRobux - priceInRobux
				err.TextColor3 = Color3.new(0, 0.333333, 0)
				err.Text = "Gamepass added to queue! Don't leave the game because it will remove it from queue!"
			else
				err.Text = "Gamepass price is not within the allowed values."
			end
		else
			err.Text = "Gamepass value is more than player's Robux Earned value."
		end
	else
		err.Text = "Gamepass isn't owned by user " .. plr.Name
	end
end)

If you need the full code, please ask for it trought DMs or in replies.

Regards,
fiftyseven.

1 Like

Is there any reason why you’re using HttpService with a HTTP proxy over MarketplaceService:GetProductInfo? It seems like all the data you need from the HTTP request is available in the return data from this method.

1 Like

i didn’t really knew I could do it using MarketplaceService. Thanks.

1 Like

This needs to be in #help-and-feedback:scripting-support

1 Like

@Thundermaker300 now i get this error:
19:58:11.961 Argument 1 missing or nil - Server - Game:26
code:

game.ReplicatedStorage.GetPayouts.OnServerEvent:Connect(function(plr)
	local gamePassId = tonumber(plr.PlayerGui.GameUI.GetPayoutsFrame.GamepassId.Text)
	local err = plr.PlayerGui.GameUI.GetPayoutsFrame.Error
	local details = game.MarketplaceService:GetProductInfo(gamePassId, Enum.InfoType.GamePass)
	
	if details["Creator"]["Id"] == plr.UserId and details["PriceInRobux"] == 5 or 10 or 25 or 50 or 100 or 500 or 1000 and details["CanBeSoldInThisGame"] then
		err.Visible = true
		err.TextColor3 = Color3.new(0.333333, 1, 0)
		err.Text = "All tests passed successfully, gamepass added to the queue. Don't leave the game to recive the payout."
	else
		err.Visible = true
		err.TextColor3 = Color3.new(1, 0, 0)
		err.Text = "Oops! Something's wrong. Make sure you are following the description!"
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.