So I’m working on a music script with requests and I’m a bit rusty with dev products but somehow the id is coming up as nil even though it plays on the script?
server script:
marketplaceService.ProcessReceipt = function(purchaseInfo)
local player = players:GetPlayerByUserId(purchaseInfo.PlayerId)
local songId
events.paidSong.OnServerEvent:Connect(function(player, id)
songId = tonumber(id)
end)
script.paidPlay.Value = true
if infoSong.IsPlaying == true then
infoSong:Stop()
end
if songId ~= nil then
infoSong.SoundId = "rbxassetid://" .. songId
elseif songId == nil then
repeat wait() until songId ~= nil
end
if not infoSong.IsLoaded then
infoSong.Loaded:Wait()
end
events.changeSong:FireAllClients(songId)
infoSong:Play()
if songId ~= nil then
print("PaidID is nil!")
paidId = songId
elseif songId == nil then
repeat wait() until songId ~= nil
print("Paid ID is: "..songId)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
while wait() do
if script.paidPlay.Value == false then
local randomSongChosen = math.random(#songs)
local songChoice = songs[randomSongChosen]
infoSong.SoundId = "rbxassetid://" .. songChoice
if not infoSong.IsLoaded then
infoSong.Loaded:Wait()
end
events.changeSong:FireAllClients(songChoice)
infoSong:Play()
repeat wait() until infoSong.IsPlaying == false
elseif script.paidPlay.Value == true then
repeat wait() until infoSong.IsPlaying == false
if paidId ~= nil then
if infoSong.SoundId ~= "rbxassetid://" .. paidId then
script.paidPlay.Value = false
end
elseif paidId == nil then
repeat wait() until paidId ~= nil
print("Paid ID is: "..paidId)
end
end
end
local script:
script.Parent.Frame.RequestButton.MouseButton1Click:Connect(function()
if script.Parent.Frame.SongID.Text ~= "Song ID" then
local id = script.Parent.Frame.SongID.Text
if tonumber(id) then
local player = players.LocalPlayer
marketplaceService:PromptProductPurchase(player, skipSongProduct)
events.paidSong:FireServer(id)
else
script.Parent.Frame.SongID.Text = "Please input a number!"
end
end
end)
This is the latest output I’m getting
PaidID is nil! - Server - musicHandler:54
14:59:43.542 Paid ID is: 298260734 - Server - musicHandler:83
14:59:57.942 PaidID is nil! (x3) - Server - musicHandler:54
I’m stumped, hopefully, someone can spot what’s wrong with my awful logic since I haven’t made a music script in a long time.
Edit: Forgot to add that if I wait around 10 seconds or so and run through the purchase again it has better odds of succeeding, and if it fails once the next purchase without payment will play the id if that’s even a good way to describe it. as well as my music not resuming after purchase which again is most likely caused by my awful logic. And the script sections are the ones that handle the purchasing and song playing.