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
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')