Attempt to index number with GetJoinData when transferring data

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)

on this line

websiteUsername = player:GetJoinData().LaunchData,

I am getting the error "attempt to index number with GetJoinData, this is very confusing as there are no numbers in the joinData.

Anyone know a solution to this?

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)

GetPlayerByUserId is not a valid member of Players

I had a typo in the code:

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)