Update: Solved by @killerbrenden

Explanation: So I am trying to make a top donator leaderboard and when the player donated, it will run a "ProcessReceipt" function. However, inside the function, I got another "UpdateLeaderBoard()" function and I tried to print "Updating LeaderBoard..." when the function receives signal but it doesn't print. So I doubt that 2 functions can't be together...?

Here's the script (This script is kinda long, please read from line 35 onwards if you do not want to waste time reading the whole script):

local MarketPlaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local RobuxDataStore = DataStoreService:GetOrderedDataStore("RobuxDateStore")
local RobuxDonateEvent = game:GetService("ReplicatedStorage"):WaitForChild("EventsFolder"):WaitForChild("RobuxDonateEvent")

local function UpdateLeaderBoard()
	print("Updating LeaderBoard..")
	local Success, ErrorMessage = pcall(function()
		local Data = RobuxDataStore:GetSortedAsync(false, 15)
		local RobuxDSPage = Data:GetCurrentPage()
		for RobuxDonated, data in ipairs(RobuxDSPage) do
			local Username = game:GetService("Players"):GetNameFromUserIdAsync(tonumber(data.key))
			local RobuxAmount = data.value
			local IsOnLeaderBoard = false
			for i, v in pairs(workspace:WaitForChild("GlobalLeaderboard"):WaitForChild("lbGUI"):WaitForChild("Holder"):GetChildren()) do
				if v.Player.Text == Username then
					IsOnLeaderBoard = true
					break	
				end
			end
			if RobuxAmount and IsOnLeaderBoard == false then
				local ClonelbFrame = game:GetService("ServerStorage"):WaitForChild("lbFrame"):Clone()
				ClonelbFrame.Player.Text = Username
				ClonelbFrame.Amount.Text = RobuxAmount
				ClonelbFrame.Position = UDim2.new(0, 0, ClonelbFrame.Position.Y.Scale + (0.08 * #workspace:WaitForChild("GlobalLeaderboard"):WaitForChild("lbGUI"):WaitForChild("Holder"):GetChildren()), 0)
				ClonelbFrame.Parent = workspace:WaitForChild("GlobalLeaderboard"):WaitForChild("lbGUI"):WaitForChild("Holder")
			end
		end
	end)
	if not Success then
		error(ErrorMessage)
	end
end
 
local function processReceipt(ReceiptInfo)
	local PlayerUserId = game:GetService("Players"):GetPlayerByUserId(ReceiptInfo.PlayerId)
	if not PlayerUserId then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	print("Player Donated Robux!")
	RobuxDonateEvent:FireClient(PlayerUserId)
	while true do
		for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
			RobuxDataStore:IncrementAsync(ReceiptInfo.PlayerId, ReceiptInfo.CurrencySpent)
		end
		for _, Frame in pairs(workspace:WaitForChild("GlobalLeaderboard"):WaitForChild("lbGUI"):WaitForChild("Holder"):GetChildren()) do
			Frame:Destroy()
		end
		UpdateLeaderBoard()
		wait(10)
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketPlaceService.ProcessReceipt = processReceipt

3 comments

1

Well, the thing is that it's a while loop, so the PurchaseGranted (Line 52) is never ran. So, you could use coroutine or the spawn(function() to create a new thread for the while loop to keep the process going? Not exactly sure if this will fix you're issue.

0

Nope. coroutine.warp does not solve it. So I used spawn function instead. But I got another problem tho, it prints not success on line 31(i changed to print("Not Success")), any idea why?

0

Sorry i changed to error(ErrorMessage), the error is "Argument 1 missing or nil" on line 31 and 49. If you have the answer can you post it, including the one you said above so i can accept it if solved?