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

I am trying to make it so if you buy a Dev Product, you get awarded a badge. See anything wrong?

Someone helped me with this before, but I had a hard time changing it. If you do see a problem, please tell me which lines to change. I believe the problem is on lines 13-14. Thanks!

local badgeservice = game:GetService("BadgeService")

local id = 2124574372 --- Put Badge ID here

local MarketplaceService = game:GetService("MarketplaceService")

local players = game:GetService("Players")

local ProductID = 98389501 --- Product ID Here

local function processReceipt(receiptInfo) 

    local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then


    return Enum.ProductPurchaseDecision.NotProcessedYet 

    end


badgeservice:AwardBadge(plr. UserId,id)   

    end

    return Enum.ProductPurchaseDecision.PurchaseGranted

end

---e 

MarketplaceService.ProcessReceipt = processReceipt

2 answers

✓ Accepted answer

I helped you before, and you didnt remove the excessive end of the previous if statement you put there, next time also include the error and which line errors

6 comments

0

The problem is, when I remove the previous end statement. The word "plr" in line 22, becomes an error.

0

plr is never defined and look at my post for more info as there is more errors

0

yes because you used the plr variable but you never defined that variable but you did define player use player instead or receiptInfo.PlayerId which is what i said on discord not plr.UserId

0

Another error I was able to find, if you look at the Dev Console it says, "Players:GetUserIdFromName() failed because user doesn't exist". How do you prevent that?

0

thats a line from a different script, this one doesnt have that line but you probably used the wrong method cuz i cant even find that one but i did find this one GetUserIdFromNameAsync https://developer.roblox.com/en-us/api-reference/function/Players/GetUserIdFromNameAsync

0

Thanks for the help, but for some reason it still won't award the badge. I don't see any errors, which leaves me wondering why it won't award the badge.

The Dev Wiki says the arguments for the function AwardBadge is (UserId,badgeId) but you have (Player,UserId,badgeId) try doing > badgeservice:AwardBadge(PlayerId,id)

2 comments

0

wrong he/she put a . between not a comma

0

sorry its receiptInfo.PlayerId

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