Chat Commands [Open Source]

Hey everyone, It’s me again Nehoray

I made Admin Commands that can be executed through Chat

Setup
// Username Version

Start by creating Server Script inside ServerScriptService

Copy and paste this code to the script you just created!

local Admins = {"nehoray1200","Username","Username"} -- Put Here Admins

local BanDatabase = game:GetService("DataStoreService"):GetDataStore("Commands_Data")

local currency = nil -- If nil It will detect automatically

local MarketPlaceService = game:GetService("MarketplaceService")

function CheckCurrency()
	wait(1)
	if currency ~= nil then return end
	for _, plr in pairs(game.Players:GetPlayers()) do
		if plr:FindFirstChild("leaderstats") then
			for i, value in pairs(plr:FindFirstChild("leaderstats"):GetChildren()) do
				if i == 1 and value:IsA("IntValue") or value:IsA("NumberValue") then
					currency = value.Name
				elseif i > 1 then
					currency = nil
					print("Too Many Currencies! Please Change It")
				end
			end
		end
	end
end

function Ban(player,Reason)
	local PlayerId = game.Players:GetUserIdFromNameAsync(player.Name)
	local success, errormessage = pcall(function()
		BanDatabase:SetAsync(PlayerId.."_BanData",true)
	end)
	if success and PlayerId ~= game.CreatorId then
		player:Kick("You're Banned! Reason: ".. Reason)
	end
end

function CheckBan(player)
	local data
	local success, errormessage = pcall(function()
		data = BanDatabase:GetAsync(player.UserId.."_BanData")
	end)
	if success and data ~= nil and data and player.UserId ~= game.CreatorId then
		player:Kick("You're Banned!")
	end
end

game.Players.PlayerAdded:Connect(function(player)
	CheckBan(player)
	CheckCurrency()
	for i, Admin in pairs(Admins) do
		if player.Name == Admin then
			player.Chatted:Connect(function(message)
				local msg = string.lower(message)
				
				local msgSplit = msg:split(" ")
				
				-- /kick nehoray1200
				if msgSplit[1] == "/kick" and msgSplit[2] ~= nil then
					for _, plrs in pairs(game.Players:GetPlayers()) do
						local plr = string.lower(plrs.Name)
						if string.find(plr,string.lower(msgSplit[2])) then
							local playerFound = game.Players:FindFirstChild(plr)
							if playerFound then
								playerFound:Kick("You Got Kicked")
							end
						end
					end
				elseif msgSplit[1] == "/ban" and msgSplit[2] ~= nil and msgSplit[3] ~= nil then
					for _, plrs in pairs(game.Players:GetPlayers()) do
						local plr = string.lower(plrs.Name)
						if string.find(plr,string.lower(msgSplit[2])) then
							local playerFound2 = game.Players:FindFirstChild(plr)
							if playerFound2 then
								print("Ban")
								Ban(playerFound2,msgSplit[3])
							end
						end
					end
				elseif msgSplit[1] == "/shutdown" then
					for i, plr in pairs(game.Players:GetPlayers()) do
						plr:Kick("Server Shutdown")
						wait(0.5)
					end
				elseif msgSplit[1] == "/bring" and msgSplit[2] ~= nil then
					for _, plrs in pairs(game.Players:GetPlayers()) do
						local plr = string.lower(plrs.Name)
						if string.find(plr,string.lower(msgSplit[2])) then
							local lowerPlayer3 = string.lower(msgSplit[2])
							local playerBring = game.Players:FindFirstChild(plr)
							if playerBring and playerBring.Character and playerBring.Character:FindFirstChild("HumanoidRootPart") then
								print("Bring")
								playerBring.Character:FindFirstChild("HumanoidRootPart").CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame + Vector3.new(0,15,0)
							end
						end
					end
				elseif msgSplit[1] == "/add" and msgSplit[2] ~= nil and msgSplit[3] ~= nil then
					local PlayerFound = game.Players:FindFirstChild(msgSplit[3])
					local Amount = tonumber(msgSplit[2])
					if PlayerFound and Amount then
						PlayerFound:FindFirstChild("leaderstats"):FindFirstChild(currency).Value += Amount
					end
				elseif msgSplit[1] == "/remove" and msgSplit[2] ~= nil and msgSplit[3] ~= nil then
					local PlayerFound = game.Players:FindFirstChild(msgSplit[3])
					local Amount = tonumber(msgSplit[2])
					if PlayerFound and Amount then
						PlayerFound:FindFirstChild("leaderstats"):FindFirstChild(currency).Value -= Amount
					end
				end
			end)
		end
	end
end)

Change the Admin Table to your username and your mods username

If you’ve 1 currency in the game It will detect that automatically

// UserId Version

Start by creating Server Script inside ServerScriptService

Copy and paste this code to the script you just created!

local Admins = {1,2,3} -- Put Here Admins ID

local BanDatabase = game:GetService("DataStoreService"):GetDataStore("Commands_Data")

local currency = nil -- If nil It will detect automatically

local MarketPlaceService = game:GetService("MarketplaceService")

function CheckCurrency()
	wait(1)
	if currency ~= nil then return end
	for _, plr in pairs(game.Players:GetPlayers()) do
		if plr:FindFirstChild("leaderstats") then
			for i, value in pairs(plr:FindFirstChild("leaderstats"):GetChildren()) do
				if i == 1 and value:IsA("IntValue") or value:IsA("NumberValue") then
					currency = value.Name
				elseif i > 1 then
					currency = nil
					print("Too Many Currencies! Please Change It")
				end
			end
		end
	end
end

function Ban(player,Reason)
	local PlayerId = game.Players:GetUserIdFromNameAsync(player.Name)
	local success, errormessage = pcall(function()
		BanDatabase:SetAsync(PlayerId.."_BanData",true)
	end)
	if success and PlayerId ~= game.CreatorId then
		player:Kick("You're Banned! Reason: ".. Reason)
	end
end

function CheckBan(player)
	local data
	local success, errormessage = pcall(function()
		data = BanDatabase:GetAsync(player.UserId.."_BanData")
	end)
	if success and data ~= nil and data and player.UserId ~= game.CreatorId then
		player:Kick("You're Banned!")
	end
end

game.Players.PlayerAdded:Connect(function(player)
	CheckBan(player)
	CheckCurrency()
	for i, Admin in pairs(Admins) do
		if player.UserId == Admin then
			player.Chatted:Connect(function(message)
				local msg = string.lower(message)
				
				local msgSplit = msg:split(" ")
				
				-- /kick nehoray1200
				if msgSplit[1] == "/kick" and msgSplit[2] ~= nil then
					for _, plrs in pairs(game.Players:GetPlayers()) do
						local plr = string.lower(plrs.Name)
						if string.find(plr,string.lower(msgSplit[2])) then
							local playerFound = game.Players:FindFirstChild(plr)
							if playerFound then
								playerFound:Kick("You Got Kicked")
							end
						end
					end
				elseif msgSplit[1] == "/ban" and msgSplit[2] ~= nil and msgSplit[3] ~= nil then
					for _, plrs in pairs(game.Players:GetPlayers()) do
						local plr = string.lower(plrs.Name)
						if string.find(plr,string.lower(msgSplit[2])) then
							local playerFound2 = game.Players:FindFirstChild(plr)
							if playerFound2 then
								print("Ban")
								Ban(playerFound2,msgSplit[3])
							end
						end
					end
				elseif msgSplit[1] == "/shutdown" then
					for i, plr in pairs(game.Players:GetPlayers()) do
						plr:Kick("Server Shutdown")
						wait(0.5)
					end
				elseif msgSplit[1] == "/bring" and msgSplit[2] ~= nil then
					for _, plrs in pairs(game.Players:GetPlayers()) do
						local plr = string.lower(plrs.Name)
						if string.find(plr,string.lower(msgSplit[2])) then
							local lowerPlayer3 = string.lower(msgSplit[2])
							local playerBring = game.Players:FindFirstChild(plr)
							if playerBring and playerBring.Character and playerBring.Character:FindFirstChild("HumanoidRootPart") then
								print("Bring")
								playerBring.Character:FindFirstChild("HumanoidRootPart").CFrame = player.Character:FindFirstChild("HumanoidRootPart").CFrame + Vector3.new(0,15,0)
							end
						end
					end
				elseif msgSplit[1] == "/add" and msgSplit[2] ~= nil and msgSplit[3] ~= nil then
					local PlayerFound = game.Players:FindFirstChild(msgSplit[3])
					local Amount = tonumber(msgSplit[2])
					if PlayerFound and Amount then
						PlayerFound:FindFirstChild("leaderstats"):FindFirstChild(currency).Value += Amount
					end
				elseif msgSplit[1] == "/remove" and msgSplit[2] ~= nil and msgSplit[3] ~= nil then
					local PlayerFound = game.Players:FindFirstChild(msgSplit[3])
					local Amount = tonumber(msgSplit[2])
					if PlayerFound and Amount then
						PlayerFound:FindFirstChild("leaderstats"):FindFirstChild(currency).Value -= Amount
					end
				end
			end)
		end
	end
end)

Change the Admin Table to your UserId and your mods UserId

If you’ve 1 currency in the game It will detect that automatically

Bugs

If you found a bug you can leave a report down here or send me a DM in the Devforum

Commands

Commands List:

--[[
All Commands
- /bring Username -- Bring the player
- /add 50 Username -- Add 50 Cash value
- /remove 50 Username -- Remove 50 Cash value
- /ban Username Reason -- Ban The player
- /kick Username -- Kick the user
- /shutdown -- Kick all players from the server

That's all more may come!
--]]

I hope you found that useful thanks for reading! :grinning:
If you’ve any suggestions or Ideas for improvement leave it below! :smiley: :wave:

18 Likes

Thanks for much! I’ll be using these in my games :grin: :call_me_hand:

2 Likes

Forgot to ask, but would you mind if I made this my own model? I’ll obviously give credits.

1 Like

Can you explain more about that?

1 Like

Meaning I would make this script, and I would save to Roblox as a model.

1 Like

Oh Yea Sure, Why not It’s open source mean you can do whatever you want with that

It will be nice If you credit but you don’t have to :wave:

1 Like

Ok good to know :+1: Thanks so much

2 Likes

It seems good, but its a good practice to use ID’s instead of Usernames.

3 Likes

Also, were can I the admin cmds for the chat?

2 Likes

I don’t see the difference between using Usernames or ID’s, both do checks and provide user validation.

(I hope it make sense)

1 Like

Can you re write that, I didn’t understood that

1 Like

But you can change your Username :wink:.

2 Likes

So what’s the problem?

Should I release the same script just with ID check instead of Username?

1 Like

You can check here how I did that.

1 Like

I just asked If I should release second version with ID checks?

Sorry, of course checking by Username is not good practice!

1 Like

Ok I will release it Today maybe

1 Like

Done! It’s should be ok, Let me know If you found any bug

1 Like

There’s a big difference, there’s an exploit that lets you take other peoples usernames.
(4) The SCARIEST Arsenal Hack… (ROBLOX) - YouTube

You should always use ID’s instead of usernames, this exploit was not only for arsenal but if arsenal used Usernames then he could get access to the admin panel. This exploit is patched but I’m sure some people have some sort of access to it still. Usernames can also be changed so you will have to go back to all the scripts and change everything, oh what a pain that would be! :sweat_smile:

My point its for anything involving a players data such as: Bans, Admin, and so on, should be be put through User ID’s and not usernames.

1 Like

I assume you can configure where the cash is. (And that you use :FindFirstChild() to avoid errors in case there is no cash value where you are looking).

1 Like