Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I can't figure this loop out it can't be removed without wrecking everything else?

I can't figure out how to remove this loop without wrecking everything can someone help?

game:GetService("MarketplaceService").ProcessReceipt = function(Info)
	for i,v in pairs(game.Players:GetPlayers()) do -- Loop
		if Info.PlayerId == v.UserId then
			local Data = v:FindFirstChild("Data")
			if Data then
				if Info.ProductId == 179386976 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 50
				elseif Info.ProductId == 179387184 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 100
				elseif Info.ProductId == 179387310 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 250
				elseif Info.ProductId == 179387552 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 500
				elseif Info.ProductId == 179387687 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 1000
				elseif Info.ProductId == 179388074 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 2500
				elseif Info.ProductId == 179388286 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 500
				elseif Info.ProductId == 179388406 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 1000
				elseif Info.ProductId == 179388772 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 5000
				elseif Info.ProductId == 179388926 then
					Data.Stats.Gold.Value = Data.Stats.Gold.Value + 10000
				end
				game.ReplicatedStorage.Events.UpdateLevel:FireClient(v)
			end
		end
	end
end

1 answer

Instead of looping through all the players and checking their user ID, find the player using the following:

From the wiki:

local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)

http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/ProcessReceipt

(this can replace line 2 and 3, and remove the corresponding 'end'-statements at the end.. and of course name the variable v or change the occurences of v in line 4 and 27 to 'player')

3 comments

0

I tried doing what you said but it only disabled the function of being able to purchase the object

0

I'm guessing the whole script broke because it's not "receiptInfo" but "Info".. so:

0

local player = game:GetService("Players"):GetPlayerByUserId(Info.PlayerId)

This discussion is preserved as it was. New answers, comments, and votes are closed.