I am attempting to make my own admin script. I have a command set up to kill a specified player, which works and all, but I have also set it up so if the second word is equal to 'me' then it will kill the player who sent the message.
It works if I put another player's name, but not if I put 'me', I believe it is something to do with the string.sub, as I don't really know how to use it properly. I have no errors in the output. Any help is appreciated, thanks.
local Admins = { ["19498972"] = true, } local prefix = ";" local commandTable = {} function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function commandTable.kill(message, player) if string.sub(message, 7, 8) == "me" then player.Character:BreakJoints() else victim = findPlayer(message) if victim and victim.Character then victim.Character:BreakJoints() end end end game.Players.PlayerAdded:Connect(function(player) if Admins[tostring(player.UserId)] then player.Chatted:Connect(function(message) local command, argument = message:match(prefix.."(.+) (.+)") if command and commandTable[command] then commandTable[command](argument, player) end end) end end)
The error, I believe is on line 17.
So i just looked into your script and saw that you are putting the command and arguments in 2 Values, command
and argument
, then you're checking from the start of position 7
if the string is me
, which is not.
In short: You gave the Script an wrong start position to check for your "target".
If you would use if string.sub(message, 1, 2) == "me" then
then it would recognize that you are selecting yourself.
Here is the full code, and sorry if you didn't understand a single bit, first time helping someone
local Admins = { ["19498972"] = true, } local prefix = ";" local commandTable = {} function findPlayer(name) for _, player in ipairs(game.Players:GetPlayers()) do if player.Name:lower() == name:lower() then return player end end end function commandTable.kill(message, player) if string.sub(message, 1, 2) == "me" then player.Character:BreakJoints() else local victim = findPlayer(message) if victim and victim.Character then victim.Character:BreakJoints() end end end game.Players.PlayerAdded:Connect(function(player) if Admins[tostring(player.UserId)] then player.Chatted:Connect(function(message) local command, argument = message:match(prefix.."(.+) (.+)") if command and commandTable[command] then commandTable[command](argument, player) end end) end end)