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

Making a roblox developer products script?

I've made this script for somebody and I do not know if it will work or not. can somebody please tell me if it will work and if it wont, How to fix it? Thanks.

local id = script.Parent.ProductID

function onClicked (mouse)
    local Humanoid = mouse.Parent:FindFirstChild("Humanoid")
    if (Humanoid ~= nil) then
        local Player = game.Players:GetPlayerFromCharacter(mouse.Parent)
        game:GetService("MarketplaceService"):PromptProductPurchase(Player, id.Value)
    end
end
script.Parent.ClickDetector.MouseClick:connect (onClicked)

1 answer

The MouseClick event in ClickDetector already returns the player. So, you can just define the player from the playerWhoClicked argument.

Here. Let me fix the script for you!

local id = script.Parent.ProductID

function onClicked (PlayerWhoClicked)
    if PlayerWhoClicked then -- Check if player is here! :)
        game:GetService("MarketplaceService"):PromptProductPurchase(PlayerWhoClicked, id.Value)
    end
end
script.Parent.ClickDetector.MouseClick:connect (onClicked)

Any questions? Leave them in the comments. Thanks!

2 comments

0

I believe that there are 2 scripts for it, What should the other one say?

0

this is the first script. where is your OTHER script that handles the purchase?

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