How to make a server notification if a player buys something your game like a shirt!

  1. What do you want to achieve?

How to make a server notification if a player buys something your game like a shirt!

  1. What is the issue?

The issue is I have looked all over but can’t find how to!

  1. What solutions have you tried so far?

I tried looking on dev forums!

Thank you in advance!

1 Like

You can either make a GUI notification show at the bottom of the screen or have the system send a message to the chat.

for _, player in pairs (game.Players:GetChildren()) do
local playerGui = player.PlayerGui
end

This will access the PlayerGui of every player on the server in a loop.

This is not what he meant, he wants to know how you could know when the player buys the shirt and then display it in a GUI as a server notification.

I am pretty sure its possible if the purchase was made in game, I might be wrong because I haven’t really worked with shirt purchases, but there are marketplace events that allow you to know if the purchase went through. I will get back to you shortly.

Okay, so you can use MarketPlaceService .

There is this event called “PromptPurchaseFinished”, you can use this to check if the player bought the shirt and then fireallclients using a remote event to show the servernotification to everyone.

local MarketPlaceService = game:GetService("MarketplaceService")
local ShirtID = 00000 -- put your shirt id here

MarketPlaceService.PromptPurchaseFinished:Connect(function(UserId,ProductId,IsPurchased)
	if ProductId == ShirtID and IsPurchased then
		local playerName = game.Players:GetPlayerByUserId(UserId).Name
		NotificationEvent:FireAllClients(playerName)
	end
end)

Unable to cast Instance to int64
Line 7

It’s pseudocode, @CelestialHonour made an example, not 100% working code. You’re going to have to build on his code to make your own, add RemoteEvents and so on.

2 Likes

Well, you have to define the event and work on the server notification code, I cannot help you with the whole thing. I did my best and showed you the path, you just gotta make remote events and work on the local script in gui. :smile:

1 Like

Add RemoteEvent Called ‘PurchaisedNotification’ in ReplicatedStorage

ServerScript:

local ms = game:GetService("MarketplaceService")
local PurchaseId = 1233838337 -- Your Shirt ID here
ms.PromptPurchaseFinished:Connect(function(plr, purchaseid, purchased)
	if purchaseid == PurchaseId and purchased then
		local plrName
		for  _, v in pairs(game.Players:GetPlayers()) do
			if v.UserId == plr then
				plrName = v.Name
			end
		end
		game.ReplicatedStorage.PurchaisedNotification:FireAllClients({
			Text = ("Message Here!");
			Color = Color3.fromRGB(206, 165, 255);
			Font = Enum.Font.SourceSansBold;
			TextSize = 18
		})
	end
end)

Add LocalScript in StarterGui:

game.ReplicatedStorage.PurchaisedNotification.OnClientEvent:Connect(function(data)
   game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", data)
end)
1 Like

This works but is there anyway I could like make it say in the message the player who bought the shirt there name would come and it would say bought a shirt

with your own gui?
(char limit)

Like something like this

	Text = (plrName.."Bought a shirt!");

Then you can change that line maybe

There I did it

Text = (plr.Name.." Bought a shirt!");

actually, plr return player’s UserId.