players = game:GetService("Players") admins = {["Player"] = true ; } players.PlayerAdded:connect(function(newPlayer) if admins[newPlayer.Name] then newPlayer.Chatted:connect(function(msg, speaker) if string.sub (msg, 1, 6) == ":kill " then for _,v in pairs (players:GetPlayers()) do if v.Name:match(string.lower(msg, 6, string.len(msg))) then v.Character.Humanoid.Health = 0 end end end end) end end)
Not sure what I'm doing wrong. I am trying to make it so that I don't have to type the full name for it to identify the player that I'm trying to kill.
players = game:GetService("Players") admins = {Player = true} players.PlayerAdded:connect(function(newPlayer) if admins[newPlayer.Name] then newPlayer.Chatted:connect(function(msg) if string.lower(msg):sub(1, 6) == ":kill " then for _, player in pairs (players:GetPlayers()) do if player.Name:sub(1, #msg:sub(7)):match(msg:sub(7)) then player.Character.Humanoid.Health = 0 end end end end) end end)
Let's jump to lines 7 and 9 to see what they mean. Line 7:
if string.lower(msg):sub(1, 6) == ":kill " then
First, we have string.lower(msg)
. That means we're taking into account that the admin might be saying :Kill Pla
or :KILL Pla
. We then get the first 6 letters of that message: :kill
. If that's the case, we move on.
if player.Name:sub(1, #msg:sub(7)):match(msg:sub(7)) then
We have msg:sub(7). That is, every character in msg from the 7th onward. Let's say that's "Pla". The length of "Pla" is 3. So, we want to see if the substring of a player's name from 1 to 3 is "Pla". If that's the case, we kill the dude.
Note that this will kill everyone who matches the shortened name. If you have 4 guests on your server, you can say :kill Guest
to kill them all.
This should do it.
players = game:GetService("Players") admins = {["Player"] = true ; } players.PlayerAdded:connect(function(newPlayer) if admins[newPlayer.Name] then newPlayer.Chatted:connect(function(msg, speaker) if string.sub(string.lower(msg),1,6) == ":kill" then local player = findplayer(string.sub(msg,6),speaker) if player ~= 0 then for i = 1,#player do- if player[i].Character ~= nil then local human = player[i].Character:FindFirstChild("Humanoid") if human ~= nil then human.Health = 0 end end end end end
Hope it does the job for you.