Chat Shop Commands

You would have to supply the callback function for the notification. This post has an example of how to apply it:

You would then do what you did for the chat script and have an if statement that compares the result:

function bindable.OnInvoke(response) -- code taken from the above post
    if response == "Yes" then
        -- Fire a remote to the server to give the coil
    else
        -- Player selected no, therefore do nothing
    end
    print(response .. " chosen")
end
2 Likes

what would the bindable mean? and where would it go? it comes up as an unknown global for me

1 Like

Bindable is an actual instance object, its used to send data between same type scripts (such as server to server or local to local). Could you send the current code block you have?

1 Like

Here you go (need a couple more letters for this to send in):

Notif1 - Roblox Studio 1_21_2022 11_47_14 PM (2)

the duration is meant to be 5 minutes long, and the (300) is meant for the amount of credits needed.

1 Like

Duration represents how long the notification will remain on the players screen. I do not recommend having on screen for longer then 10 seconds. You don’t want the player to be flooded with notifications that don’t disappear for like 5 minutes. If they haven’t made a selection in like 10 seconds then just assume they don’t want to purchase.

-- This is just the same script from the forum post just slightly edited

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

	function Bind.OnInvoke(Reponse)
		if Reponse == "Yes" then
			print("fire remote to server to give coil");
		else
			print("player canceled the purchase");
		end;
	end;

	SG:SetCore("SendNotification", {
		Title = "Purchase";
		Text = "Are you sure you want to purchase an AK-47 (300)";
		Icon = "";
		Duration = 10; -- Don't leave it for 300 seconds, if the player hasn't selected anything in like 10 seconds then assume they didn't want to purchase. Don't want to flood their screen with notifications forever.
		Button1 = "Yes";
		Button2 = "No";
		
		Callback = Bind;
	});

1 Like

see this topic of mine

1 Like

thanks, I probably would have changed the duration after some major trial and error :grinning_face_with_smiling_eyes:, so is there an easy way for me to identify the player?

1 Like

Also that is a very nice post!

1 Like

Its quite easy for any local scripts. All you have to do is:

local Player = game:GetService("Players").LocalPlayer

Local player only exist on the client, trying to define local player in a server script won’t work and will result in an error. So what you would want to do is create a RemoteEvent → when the player chats the right command, fire that remote for the client that sent the chat message → have the players client listen for that event and then post the purchase notification (the one we did above) → once the player makes a selection you then fire the same remote and this time have the server listen for that event → have the server give the desired item.

1 Like

thank you

1 Like

Alright I used that thanks for the reassurance!

1 Like

I was trying to make the game just clone it out of the server storage folder, and just put it in the players backpack. Is that not efficient or something?

also I don’t know what happened but for some reason the server script will not let me clone the notification gui into the player’s PlayerGui… heres what the code looks like, its just your base code:

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

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

PS.PlayerAdded:Connect(PlayerJoined);

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

Since we are making the message lowercase, the if statement won’t be met since AK is capital. Just change it to ak-47 instead of AK-47.

1 Like

I don’t really understand – why not use a shop GUI with an open/close button, and handle the verification of the purchase on the server? Using chat commands seems to overcomplicate this purpose and doesn’t seem very productive for a consumer, not to mention it would be easier to accomplish the former. Is there a reason for this choice in design?

1 Like

It just looks cool to me. That is the entire reason.

But seriously I just do not want to make a shop since there is not downtime at all inside the game, and I just want there to be a notification since it looks cool, instead of a giant box on your screen.

1 Like

That seems to have fixed it.

Also about that.

I scripted that inside of the little notification ‘if else’ statement. Did not seem to work at all (Also as of this edit I’m going to go eat)

if Reponse == "Yes" then
		if plr.leaderstats.Cash.Value >= 300 then
			plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value - 300
			local c = SS.Weapons["AK-47"]:Clone()
			c.Parent = plr.Backpack
		end	
	else
		print("Player canceled the purchase");
	end;
1 Like

It would be better to have an ID system of sorts and utilize a RemoteFunction to determine whether the player purchased the weapon or not.
For example,

local Weapons = {
    ["AK-47"] = 47, -- Weapon name, price of weapon
}

local function RetrieveWeaponData(Arg)
    for WeaponName, Price in pairs(Weapons) do
        if WeaponName:lower():find(Arg) == 1 then
            return WeaponName, Price
        end
    end
    return nil, nil
end
...

local Arg = Msg:lower():match("%!buy (%w+)")
if Arg then
    local WeaponName, _ = GetWeaponData(Arg)
    if WeaponName then
        local NewNotif = script.Notification:Clone()
        NewNotif.WantedWeapon.Value = Weapon
        NewNotif.TextLabel.Text = "Are you sure you want to buy [" .. Weapon .. "] ?"
        NewNotif.Parent = Player.PlayerGui
    end
end
...

PurchaseWeapon.OnServerInvoke = function(Player, WeaponName)
    local WeaponName, Price = GetWeaponData(WeaponName)
    -- Verify purchase on server, and give the specified weapon
end
1 Like

That seems like a smart idea although it looks extremely confusing and

Notifications don’t work like that

That notification system seems fine to me. Simply clone the notification parent it to the player’s PlayerGui folder somewhere (so that it’s correctly rendered onto the screen) and then modify the shown GuiObjects accordingly (alter text, images etc.).

Sorry, went to bed.

The reason why its not working is because you need to give the item on the Server not the client. To do this you would have to use RemoteEvent and/or RemoteFunctions.

So right click on replicatedStorage → insert a new object (aka a remoteEvent) → name that remote whatever you want → define that remote in your notification script → have it FireServer() when player buys an item → server listens for the event → server gives item