I am trying to transfer data from roblox to my website to test a premium system where the user buys a dev product on roblox and gets premium on the website.
Here is my current code (i have removed some useless lines such as the UI creation)
local HttpService = game:GetService("HttpService")
local MarketplaceService = game:GetService("MarketplaceService")
local PremiumProductID = 1687999613
game.Players.PlayerAdded:Connect(function(player)
local joinData = player:GetJoinData()
if joinData and joinData.LaunchData then
local websiteUsername = joinData.LaunchData
print(websiteUsername)
else
print("No join data received!")
end
end)
MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, productId, isPurchased)
if productId == PremiumProductID and isPurchased then
print("purchase successful")
local data = {
websiteUsername = player:GetJoinData().LaunchData,
duration = "1 month"
}
local jsonData = HttpService:JSONEncode(data)
local response = HttpService:PostAsync("hidden for confidentiality ", jsonData)
end
end)
When encountering difficulties with parameters, always check the documentation!
You are trying to receive the parameters of “player, productId, isPurchased” from the PromptProductPurchaseFinished. However, from the documentation, the actual parameters are “userId, productId, isPurchased”
In order to get the player object, you have to use game.Players:GetPlayerByUserId(userId)
When added to your code, it will look like this:
local HttpService = game:GetService("HttpService")
local MarketplaceService = game:GetService("MarketplaceService")
local PremiumProductID = 1687999613
game.Players.PlayerAdded:Connect(function(player)
local joinData = player:GetJoinData()
if joinData and joinData.LaunchData then
local websiteUsername = joinData.LaunchData
print(websiteUsername)
else
print("No join data received!")
end
end)
MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, isPurchased)
local player = game.Players:GetPlayerFromUserId(userId)
if productId == PremiumProductID and isPurchased then
print("purchase successful")
local data = {
websiteUsername = player:GetJoinData().LaunchData,
duration = "1 month"
}
local jsonData = HttpService:JSONEncode(data)
local response = HttpService:PostAsync("hidden for confidentiality ", jsonData)
end
end)
local HttpService = game:GetService("HttpService")
local MarketplaceService = game:GetService("MarketplaceService")
local PremiumProductID = 1687999613
game.Players.PlayerAdded:Connect(function(player)
local joinData = player:GetJoinData()
if joinData and joinData.LaunchData then
local websiteUsername = joinData.LaunchData
print(websiteUsername)
else
print("No join data received!")
end
end)
MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, isPurchased)
local player = game.Players:GetPlayerByUserId(userId)
if productId == PremiumProductID and isPurchased then
print("purchase successful")
local data = {
websiteUsername = player:GetJoinData().LaunchData,
duration = "1 month"
}
local jsonData = HttpService:JSONEncode(data)
local response = HttpService:PostAsync("hidden for confidentiality ", jsonData)
end
end)