Remote Events Gives an Extra Boost Every Purchase After One is Used

Every time I use a boost, it gives an extra boost every time I purchase one again. If you don’t understand, I can reply the script of give additional details. (Ignore the fact the in the video it goes to -1, I already fixed that)

1 Like

Check your state or perhaps add a sanity check on the server

My guess is that there is a function or event that is getting looped. The first time you fire it, it works fine, however, it never returns. Maybe there is a loop in the function that is reliant on a variable to get changed, but you simultaneously fire another function, causing the looping function to fire as well as the new functions and then it stacks. I am not sure if you understood that, so let me know if you are struggling or if that is not the case.

Some code might be helpful in this case, however, it just looks like functions are getting stacked and not being returned when they complete.

EDIT:

Example of my scenario:

local remote_event = replicated_storage.Event
local variable = false

function Wait_For_Variable(value)
	while task.wait(1) do
		if variable then
			-- Do stuff
		end
	end
end

remote_event.OnServerEvent:Connect(function(player)
	Wait_For_Variable(player)
	variable = true
end)

Each time the event is fired, the function is called again, however, the last time the function was called it never returned. It kept running forever.

I understand but I don’t think there’s anything looping in the script I use.

game.MarketplaceService.ProcessReceipt = function(receiptInfo)
	local Player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)

	--Coins Boost--

	if receiptInfo.ProductId == 1352235811 then
		Player.Boosts.CoinsBoosts.Value += 1

		return Enum.ProductPurchaseDecision.PurchaseGranted
	end

	--Gems Boost--

	if receiptInfo.ProductId == 1531159021 then
		Player.Boosts.GemsBoosts.Value += 1

		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

I also have multiple coins and gems purchases in that same script with the same function just different productIds and values inside leaderstats and those work fine.

When you use the boost, are you making sure to check with the server if they are allowed to use a boost? And then deducting the value on the server? It seems like you are only checking on the client and deducting the value on the client, which won’t replicate to the server. So the server still thinks you have a boost when you go to buy another one, which is why it shows as having 2 boosts, and then 3 boosts, and so on.

That totally makes sense, I’ll try changing that and mark it as the solution if it works.

It worked, thank you so much that solved a huge issue in my game!