Chat Command Help

Hello, how would I make it print “test” is a player chatted “/vip”, but it only prints if they own a certain gamepass.

(The command should not be case sensitive so that way “/VIP”, “/Vip”, and etc. would work.)

1 Like

I can’t give you a link or a how to, but go onto youtube and search AlvinBlox and he has a pretty good admin tutorial

Well, i always tend to script my own chat systems, but on the server-side of the game, you might be able to use Player.Chatted.

A simple command system would look like this:

local MPS = game:GetService("MarketplaceService")
local GamepassId= 0 -- you put your gamepass ID here

local Commands = {
'/vip'
}

game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if table.find(Commands, string.lower(Message)) and MPS:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
print('test)
end
end
end

Im not 100% sure this will work, as i tend to script my own chat systems, but im hoping it does work.

i rewrote it but still wont work, no errors.

local MarketplaceService = game:GetService("MarketplaceService")
local GamepassId = 49631462
local Commands = {
	"/vip"	
}

game.Players.PlayerAdded:Connect(function(LocalPlayer)
	LocalPlayer.Chatted:Connect(function(Message)
		if table.find(Commands, string.lower(Message)) and MarketplaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, GamepassId) then
			print("test")
		end
	end)
end)

As i said, i dont usually use the default roblox chat system.
I also dont use MarketplaceService much either, so youre better off looking for tutorials somewhere.

1 Like

LocalPlayer? It looks like you are running this on the client, the .PlayerAdded event does not fire on the client because by the time the script runs the player will already be in the game as LocalScripts are put into the player instance by the server after the player joins so you must run this on the server.

Should be A LocalScript In StarterPlayerScripts.

local VIPGamepassID = 0000000 -- Enter your VIP Gamepass ID
local Player=game.Players.LocalPlayer

Player.Chatted:Connect(function(msg)
   if #string.split(msg," ")==1 then
       if string.split(msg," ")[1] == "/vip" then
           print("test")
       end
   end
end)
1 Like

the argument is passed with the name LocalPlayer,
im pretty sure his script is running on the server and not the client.

I wanted to ask because i don’t see any reason to name the argument LocalPlayer if the script is running on the server

Correct, i wrote it as a server-script because thats what commands should be handled on.
Still, im not used to scripting chat commands or anything.

This seems to work, although how would you add :lower to it so that way “/VIP”, “/Vip”, and etc would also print test.

We can use .lower() To Lowecase the Entered Chat Message And Check if it matches /vip
new working script :

local VIPGamepassID = 0000000 -- Enter your VIP Gamepass ID
local Player=game.Players.LocalPlayer

Player.Chatted:Connect(function(msg)
	if #string.split(msg," ")==1 then
		if string.split(msg," ")[1].lower(string.split(msg," ")[1]) == "/vip" then
			print("test")
		end
	end
end)
1 Like

Part of the code has been snipped out but how would I also update the bubble chat colors to the server? It only changes on the Client. I would use a Remote Event but I am not sure what would be in the code.

LocalPlayer.Chatted:Connect(function(Message)
	if #string.split(Message, " ") == 1 then
		if string.split(Message, " ")[1].lower(string.split(Message, " ")[1]) == "/premium" or string.split(Message, " ")[1].lower(string.split(Message, " ")[1]) == "/vip" then
			if MarketplaceService:UserOwnsGamePassAsync(LocalPlayer.UserId, GamepassId) then
				if Toggle == true then
					ChatService:SetBubbleChatSettings(Settings)
					Toggle = false
				elseif Toggle == false then
					ChatService:SetBubbleChatSettings(VIPSettings)
					Toggle = true
				end
			end
		end
	end
end)

You can listen for Chatted on the server.

1 Like