So in admin commands, you can type something like ":kill pla" and it would kill someone named "Player" how can I do this?
This is my script: (any help appreciated as usual)
local a = false local oa = false local pref = "." local owners = {"Hyphonated", "Player"} local admins = {"", ""} game.Players.PlayerAdded:connect(function(p) for _,owner in pairs(owners) do if p.Name == owner then oa = true a = true print(oa, a) end end end) game.Players.PlayerAdded:connect(function(p) for _,admin in pairs(admins) do if p.Name == admin then a = true end end end) game.Players.PlayerAdded:connect(function(p) p.Chatted:connect(function(msg) if string.sub(msg, string.len(pref), 6) == pref.."kill " and a == true then if game.Players:FindFirstChild(string.sub(msg, 7, string.len(msg))) then game.Players:FindFirstChild(string.sub(msg, 7, string.len(msg))).Character.Humanoid.Health = 0 end end end) end)
words = {} function findw(text, separator) local words = {} for word in text:gmatch("[^" .. " " .. "]+") do table.insert(words, word) end return words end
Explaination, what this does is it seperates every space into a table so you can seperate and find the things so if it gives you part of name then you would do
function compare(word) for i,v in pairs(game.Players:GetChildren()) do if v:sub(1,#word):lower() == word:lower() then break return v end end player = compare("devs") -- Not fully devSeldom ps not cap sensitive print(player.Name) --Would print devSeldom since it found me
What this does is it compares the strings of the word you give it so example ^
adminkey = ";" admincommands = {"kill", "teleport", "random"} function findcommand(word, playername) if word:sub(1,1) == adminkey then for i,v in pairs(admincommands) do return v break end end
would return the command
Example
local player = game.Players.LocalPlayer repeat wait() until player.Character local variables = { Admins = ["devSeldom","Hyphonated"], Commands = ["Kill"] IsAdmin = false FireCode = ":" } --Checks if the player is a admin for i,v in pairs(variables.Admins) do if player.Name == v then variables.IsAdmin = true end --Finds the command function findcommand(word, playername) if word:sub(1,1) == adminkey then for i,v in pairs(variables.Commands) do return v break end end --Finds player and returns it function compare(word) for i,v in pairs(game.Players:GetChildren()) do if v:sub(1,#word):lower() == word:lower() then break return v end end --Creates a table function findw(text, separator) local words = {} for word in text:gmatch("[^" .. separator .. "]+") do table.insert(words, word) end return words end player.Chatted:connect(function(msg) if variables.IsAdmin == true then chattable = findw(msg, " ") command = findcommand(chattable[1]) if command == "Kill" then player1 = compare(chattable[2]) if player1 ~= nil then player1.Character.Humanoid.Health = 0 end end end end)