function itemBuy(player, itemType, item, currency, cost)
	purchasedItem = false
	marketplaceService:PromptProductPurchase(player, cost) -- Cost == ProductId
					
	local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
				
	function marketplaceService.ProcessReceipt(receiptInfo) 
		local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
		if PurchaseHistory:GetAsync(playerProductKey) then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
				 
		local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
		if not player then 
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
				 
		if receiptInfo.ProductId == cost then
			purchasedItem = true
		end
		PurchaseHistory:SetAsync(playerProductKey, true)	
		return Enum.ProductPurchaseDecision.PurchaseGranted		
	end
	print('1')
	return purchasedItem
end

buyItem.OnServerInvoke = itemBuy

Local script

function buy(itemType, item, currency, cost)
	if buyItem:InvokeServer(itemType, item, currency, cost) then
		print('123')
		playersGuns:FindFirstChild(item).Value = true
		buyButton.Visible = false
		equipButton.Visible = true
	end
end

I'm trying to return true to the player purchasing the item, so that way the RemoteFunction that's being called in the LocalScript can continue (if returned true then the code in local script conitnues) however when I return true after a player buys an item it just does nothing

2 comments

0

Maybe have a central bool Value which itemBuy writes to. Then, in the other script, yield to it with boolValue.Changed:Wait(...).

0

You are always returning a GlobalDataStore when the client invokes the server. Also, you probably don't want to define the ProcessReceipt callback every time someone invokes the remote.