Hey so I made a custom leaderboard, and I added a button called gift player stage, as its an obby game.So in this player will buy the 15 robux purchase and the player he selected should get the skip stage item, how do I make this?
tty using ordered or global datastore im not sure how but might work
but player should get it instantly and should get a message saying “they gifted u this skip stage”
You can add a LocalScript into the button, a RemoteEvent in ReplicatedStorage and a Script in ServerScriptService and in the LocalScript do this:
script.Parent.MouseButton1Click:Connect(function()
local playerToGift = --if you have a textbox just get the player's name from there with textbox.Text
local FoundPlayer = game.Players:FindFirstChild(playerToGift)
game.ReplicatedStorage.RemoteEvent:FireServer(FoundPlayer)
end)
Normal script:
local mps = game:GetService("MarketPlaceService")
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, foundPlayer)
mps:PromptPurchase(player, productID)
end)
mps.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == "productIdHere" then
--gift the stage here
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
Its a good idea but how does the server give the skip stage to the selected player?
You can use a Datastore with all the players that were gifted, increase the data value once someone bought it for someone else, and once a player joins check if they were gifted and increase the stage value for the player. But there is possibly a better method to give the stage to a selected player.
But the player should quit and rejoin, I think a better method could be create a stage value that is saved when the player leaves and increased of 1 when someone gifts a stage, after this he could create a function that checks when the value changes and if it changes the script will teleport the player to the next stage.
Yes but how it goes to the told player only?
No because if you do this the stage will be gifted to the variable “foundPlayer” wich is the player to gift the stage.
local mps = game:GetService(“MarketPlaceService”)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, foundPlayer)
mps:PromptPurchase(player, productID)
mps.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == "productIdHere" then
foundPlayer.Stage.Value += 1
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
foundPlayer.Stage.Changed:Connect(function()
--Teleport the player to the next stage here
end)
end)
Note that to use foundPlayer.Stage.Value += 1 you need an IntValue/NumberValue inside the player in the players category.