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)
endHow to set it up
- Find your UserId: open your Roblox profile on the website. The number in the address bar is your UserId.
- Add the Script to ServerScriptService and replace the 0 in ADMINS with your UserId.
- 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.
- Type !speed yourname 50 in chat.
Change it
- The check happens on the server. Players cannot give themselves admin from their own device.
- While the list only holds 0, nobody is an admin.
- To add a command, add another commands.name = function(admin, args) block.
- These commands are for the game you own. They need your chat messages to reach the server, which is how Roblox chat works by default.
More in Admin and safety
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.