I’ve recently made a Rest API and conneceted it through Roblox it’s able to sometimes get the info but if I run the line of code
Line of Code (Line 21)
local response = game:GetService("ReplicatedStorage").Purchase:InvokeServer(product.DevProduct.Value, product.ProductId.Value)
It doesn’t invoke the server and and the out put shows
HttpEroor: ConnectFail
Script ‘Player.Username.PlayerGui.Hub.Backpack.Main.ProductsFrame.ProductLoader’, Line 21
Here is the full script:
Full Script
local MarketPlaceService = game:GetService("MarketplaceService")
game:GetService("ReplicatedStorage").Products.OnClientEvent:Connect(function(products)
for productId, product in pairs(products) do
local clone = script.Parent.ProductTemplate:clone()
clone.Visible = true
clone.Parent = script.Parent
clone.Name = product.name
clone.ProductName.Text = product.name
clone.DevProduct.Value = product.developerProduct
local price = MarketPlaceService:GetProductInfo(product.developerProduct, Enum.InfoType.Product).PriceInRobux
if price == nil then
price = "Unknown"
end
clone.ProductPrice.Text = "R$ " .. price
clone.ProductId.Value = product.id
end
for i,product in pairs(script.Parent:GetChildren()) do
if product:IsA("Frame") then
product.Purchase.MouseButton1Click:Connect(function()
local response = game:GetService("ReplicatedStorage").Purchase:InvokeServer(product.DevProduct.Value, product.ProductId.Value)
if response == "owned" then
product.Purchase.Text = "Already Owned!"
end
end)
end
end
end)
Other Code
game:GetService("ReplicatedStorage").CheckLinked.OnServerInvoke = function(player)
local user = Core.fetchUser(player.UserId)
return user
end
game:GetService("ReplicatedStorage").Purchase.OnServerInvoke = function(player, DevProduct, ProductId)
if (Core.checkProductOwnership(ProductId, player.UserId).hasProductOwnership == true) then
print("owned")
return "owned"
else
MarketPlaceService:PromptProductPurchase(player, DevProduct)
end
end
Core Code
local ServerScriptService = game:GetService("ServerScriptService")
local http = require(ServerScriptService.http)
local baseURL = "http://server1.us.knovon.org:5000"
local setting = require(game:GetService("ServerScriptService"):WaitForChild("Settings"))
local hubId = setting.Hubid
local apiKey = setting.APIKey
local hub = false
if hubId == "" or apiKey == "" then
warn("lincoln | Hub ID or API Key was left empty!")
end
-- Hub
function lincoln.fetchHub(setHub)
local res = http.get(baseURL .. "/hubs/" .. hubId, {
query = {
apiKey = apiKey
}
})
if res.status_code == 200 then
if setHub == true then
hub = res:json()
end
return res:json()
else
error("lincoln | Error fetching hub. Ensure the Hub ID and API Key are correct.")
return res:json()
end
end
function lincoln.fetchProducts()
local res = http.get(baseURL .. "/hubs/" .. hubId .. "/products", {
query = {
apiKey = apiKey
}
})
if res.status_code == 200 then
return res:json()
else
error("lincoln | Error fetching products. Ensure the Hub ID and API Key are correct.")
return res:json()
end
end
-- Product
function lincoln.giveProduct(productId, discordUserId)
local res = http.post(baseURL .. "/hubs/" .. hubId .. "/products/owners", {
query = {
apiKey = apiKey
},
data = {
productId = productId,
deliveryType = 1,
userId = discordUserId
}
})
if res.status_code == 200 then
return res
else
print(res)
error("lincoln | Error giving user product.")
return res
end
end
-- User
function lincoln.fetchUser(robloxUserId)
local res = http.get(baseURL .. "/users/roblox/" .. robloxUserId)
if res.status_code == 200 then
return res:json()
else
return res:json()
end
end
function lincoln.checkProductOwnership(productId, robloxUserId)
local user = lincoln.fetchUser(robloxUserId).data.discordId
local res = http.get(baseURL .. "hubs/" .. hubId .. "/ownership/".. productId .. "/" .. user)
if res.status_code == 200 then
return res:json()
else
return res:json()
end
end
return lincoln```
The Rest API it is currently connecting to is https://server1.us.knovon.org:5522
If you can help this will really be appreciated!