Chat Shop Commands

First you have to have a Folder (I named mine Weapons) and put it in ServerStorage.

Server Script named ShopCmds (in SSS):

local PS = game:GetService("Players");

function PlayerJoined(Player)
	Player.Chatted:Connect(function(Msg)
		if string.lower(Msg) == "!buy blank" then
			local c = script.Notif:Clone()
			c.Parent = Player.PlayerGui
		end;
	end);
end;

PS.PlayerAdded:Connect(PlayerJoined);

for _, Player in ipairs(PS:GetPlayers()) do
	task.spawn(PlayerJoined, Player);
end;

Notification Script named Notif (Inside of ShopCmds script):

local SG = game:GetService("StarterGui");
local SS = game:GetService("ServerStorage");
local RS = game:GetService("ReplicatedStorage");
local Bind = Instance.new("BindableFunction");

function Bind.OnInvoke(Reponse)
	if Reponse == "Yes" then
			RS.Purchase:FireServer("blank")
	else
		print("Player canceled the purchase");
	end;
end;

SG:SetCore("SendNotification", {
	Title = "Purchase";
	Text = "Are you sure you want to purchase a blank ($100)";
	Icon = "";
	Duration = 10;
	Button1 = "Yes";
	Button2 = "No";

	Callback = Bind;
});

Separate server script named ServerPurchase (in SSS):

local Remote = game:GetService("ReplicatedStorage").Purchase
local Folder = game:GetService("ServerStorage").Weapons

Remote.OnServerEvent:Connect(function(Player, Weapon)
	print(Player, Weapon)
	local Price = Folder:FindFirstChild(Weapon).Cost.Value
	if Player.leaderstats.Cash.Value >= Price then
		Player.leaderstats.Cash.Value = Player.leaderstats.Credits.Value - Price
	local c = Folder:FindFirstChild(Weapon):Clone()
		c.Parent = Player.Backpack
	end
end)

The Cost is a IntValue inside of the tool

Thank you so much @Ze_tsu for helping me solve this!

2 Likes

Np! Goodluck with your project.