hi, i’m looking for help with scripting a situation where upon completion of a task a user is then presented with a prompt to purchase a marketplace item.
currently i have the script awarding the player a badge upon completion. how can i then also trigger a purchase prompt? will i need to create a localscript in addition to the server script?
i’ve been browsing the forum for hours but i’m new to scripting and feel like there’s some search term i’m missing! any help would be much appreciated, please let me know if any more details are needed or if there’s already a solution for this
Hii, to show a purchase prompt after awarding a badge, you’ll need two scripts: one for the server and one for the client.
In the server script, when the task is done and the badge is given, trigger an event.
-- Trigger an event after awarding the badge
game:GetService("BadgeService"):AwardBadge(player.UserId, badgeId)
-- Trigger the event for prompting purchase
game.ReplicatedStorage.PromptPurchaseEvent:Fire(player)
In the client script, listen for this event. When it’s triggered, show the purchase prompt.
-- Listen for the event to prompt purchase
game.ReplicatedStorage.PromptPurchaseEvent.OnClientEvent:Connect(function()
-- Show the purchase prompt here
game:GetService("MarketplaceService"):PromptPurchase(assetId)
end)
This way, the server handles the game logic, and the client manages the user interface.
thank you for responding! i think i’m doing something wrong, because i’ve pasted your first piece about triggering the events into where i had just the badge awarded, and the client script into a new LocalScript. it brings up this in the output window:
PromptPurchaseEvent is not a valid member of ReplicatedStorage “ReplicatedStorage”
should i be naming the LocalScript? or placing it somewhere specific? or am i misunderstanding something?
thank you for your patience! i’m very inexperienced with these kinds of scripts.
ohhh okay, thank you! i changed that and the error stopped coming up. when testing just in studio i don’t get the prompt come up but maybe i need to test it in a game?
one last question - where does the localscript need to go? and does that need to be named as well?