Skinstashery
Roblox
Home / Roblox / Studio script library / Admin commands by UserId
RB-004

Roblox admin commands by userid script

Chat commands like !kill and !speed that only you and the people you list can use.

Script type
Script
Where it goes
ServerScriptService
Category
Admin and safety

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Admin commands for YOUR game. Only the UserIds in the list can use them.
-- Type in chat:  !kill name   !heal name   !speed name 50   !kick name

-- Replace 0 with your Roblox UserId. Add more lines for helpers you trust.
-- Always use the UserId, never the username. Usernames can be changed.
local ADMINS = {
	[0] = true,
}
local PREFIX = "!"

local Players = game:GetService("Players")

-- Finds a player whose name starts with what you typed (not case sensitive).
local function findPlayer(query)
	if not query then
		return nil
	end
	query = string.lower(query)
	for _, player in Players:GetPlayers() do
		if string.sub(string.lower(player.Name), 1, #query) == query then
			return player
		end
	end
	return nil
end

local function getHumanoid(player)
	local character = player.Character
	return character and character:FindFirstChildOfClass("Humanoid")
end

local commands = {}

commands.kill = function(admin, args)
	local target = findPlayer(args[2])
	local humanoid = target and getHumanoid(target)
	if humanoid then
		humanoid.Health = 0
	end
end

commands.heal = function(admin, args)
	local target = findPlayer(args[2])
	local humanoid = target and getHumanoid(target)
	if humanoid then
		humanoid.Health = humanoid.MaxHealth
	end
end

commands.speed = function(admin, args)
	local target = findPlayer(args[2])
	local humanoid = target and getHumanoid(target)
	local speed = tonumber(args[3])
	if humanoid and speed then
		humanoid.WalkSpeed = math.clamp(speed, 0, 100)
	end
end

commands.kick = function(admin, args)
	local target = findPlayer(args[2])
	if target and target ~= admin then
		target:Kick("You were removed by the game admin.")
	end
end

local function onChatted(player, message)
	if not ADMINS[player.UserId] then
		return -- not an admin: ignore silently
	end
	if string.sub(message, 1, #PREFIX) ~= PREFIX then
		return
	end

	local args = string.split(string.sub(message, #PREFIX + 1), " ")
	local command = commands[string.lower(args[1] or "")]
	if command then
		command(player, args)
	end
end

local function onPlayerAdded(player)
	player.Chatted:Connect(function(message)
		onChatted(player, message)
	end)
end

Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
	onPlayerAdded(player)
end

How to set it up

  1. Find your UserId: open your Roblox profile on the website. The number in the address bar is your UserId.
  2. Add the Script to ServerScriptService and replace the 0 in ADMINS with your UserId.
  3. Play a test with at least one other player (Test tab, Clients and Servers, start 2 players) or use your own name as the target.
  4. Type !speed yourname 50 in chat.

Change it

More in Admin and safety

All Roblox scripts

More Roblox tools