Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago
Edited 6 years ago

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

0
I tried doing what you said but it only disabled the function of being able to purchase the object TheLuaDeveloper 5 — 6y
0
I'm guessing the whole script broke because it's not "receiptInfo" but "Info".. so: Nonaz_jr 439 — 6y
0
local player = game:GetService("Players"):GetPlayerByUserId(Info.PlayerId) Nonaz_jr 439 — 6y
Ad

Answer this question