"!rules" command for BAE 2.0

Hello! I was wondering if anyone knows how to do a !rules command in Basic Admin. If you don’t know what a !rules command is, it’s basically when you say !rules a servermessage pops up stating all the rules until all the rules are stated. If you know how to do it please reply.

4 Likes

You would have to make a plugin through basic admin for that.

1 Like
local Commands = {
	['rules'] = function(Player)
		print ('show blank to '.. Player.Name)
	end
}


game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Msg)
		if string.len(Msg) == 1 then
			return
		end
		
		if string.sub(Msg, 1,1) ~= '!' then
			return
		end 
		
		Msg = string.lower(Msg)
		
		Msg = string.sub(Msg, 2, string.len(Msg))
		
		if Commands[Msg] then
			Commands[Msg](Player)
		end
		
	
	end)
end)

When the player chats do what you want using the Player.Chatted event. To get the player object using the PlayerAdded event. Any command is obviously more then 1 letter since the prefix is already one letter, so if the message is one letter then we return. We also want our prefix to be ‘!’ so if the first character of the message is not !, then we return (stopping function exeuction in the middle). Then we make the string lower so we allow things like !rulEs, and then we sub the string from its second letter to it’s final letter since in our commands we only want the indexes to be the command name, !rules as an index of a table is yuck we want neat code, and then if there is a command like that we call it.

This isn’t the full code it’s just how to get started.

2 Likes

I can get you started with the basics. So first what you want to do is make a script in ServerScriptService. Then you want to paste the following code inside:

local prefix = "!"
--Chat Stuff
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))

--Wait for the channel 'All' to exist
if not ChatService:GetChannel("All") then
	while true do
		local ChannelName = ChatService.ChannelAdded:Wait()
		if ChannelName == "All" then
			break
		end
	end
end

local System = ChatService:AddSpeaker("System")
System:JoinChannel("All")

game:GetService("Players").PlayerAdded:Connect(function(plr) -- Runs following code for each player joined
plr.Chatted:Connect(function(msg) --Detects when a player chats
     if msg == prefix.."rules" then --Looks for "!rules"
          System:SayMessage("Rules:\n1. No bad words") --Change text to whatever
     end
end)
end)

(Some code from here)

Hope this helps! :smile: (Wrote on my phone tell me if syntax errors!)

2 Likes