What do you want to achieve? Hello, in a serverscript related to an in-game purchase, I would like to be able to detect the player in order to perform an action on him, but I do not know how to do it. Thanks
I have tried :
for i, plr in pairs(game.Players:GetPlayers()) do --But it take all player in the game
--//// i also tried
local Players = game:GetService('Players').PlayerAdded:Wait() -- But it only take the last player
Here is the function where i want to take the player :
mps.ProcessReceipt = function(Shop)
--Here i want to detect the player to put an action for him
local amount = mps:GetProductInfo(Shop.ProductId, Enum.InfoType.Product).PriceInRobux
local success, err = pcall(function()
local totalDonated = ods:GetAsync(Shop.PlayerId) or 0
ods:SetAsync(Shop.PlayerId, totalDonated + amount)
end)
return success and Enum.ProductPurchaseDecision.PurchaseGranted or Enum.ProductPurchaseDecision.NotProcessedYet
end
Yes but in a server script it is sometimes possible to have only one player, especially with Events or with game:GetService(âPlayersâ) Players.PlayerAdded:Connect(function(plr) .
Because I canât put a name on the player who is going to buy my product since I donât know him, he is one of hundreds of millions of players I canât predict. There must be a way, I hope
Hello!
Iâm pretty sure you canât get LocalPlayer on Server scripts since when you try it, it will return nil.
I suggest try using the code block listed below on a LocalScript and use an event to link the function to a ServerScript.
local Players = game:GetService(âPlayersâ).LocalPlayer
If you really want to learn more, check out the Developer Hub.
This is impossible since the mps.ProcessReceipt = function(Shop) is only accessible in a server script. So the use of an event is not possible in this case.
Same thing for the DataStore (there is one in the script)
Please read the documentation, you can find the player by accessing ReceiptInfo.PlayerId and looping through players table and see if that playerâs UserId is the same as the one on ReceiptInfo.
If this is a gamepass, I am pretty sure you can just do:
mps:PromptGamePassPurchaseFinished:Connect(function(plr, id, purchased) â First value is for the player, second is for the gamepass id, and third, to find out if it was purchased.
â Code here
end)