I am trying to make a script that kills the person you are chatting about(admin command). It works fine until I tried to add a part that lets you shorten names. I am pretty sure I did something wrong with my math since there are no errors.
local Player=game.Players.LocalPlayer Player.Chatted:connect(function(Text) if string.sub(Text,1,4)=="Kill" or "kill" or "KILL" then for i,v in pairs(game.Players:GetChildren()) do for i=7,tonumber(string.len(v.Name)),1 do local Length=tonumber(string.len(Player.Name)) if string.sub(Text,6,i)==string.sub(v.Name,1,Length-(i-6)) then --I think its something above and between[ ] v.Character.Humanoid.Health=0 end end end end end) --[["Kill tuma" 123456789]]
Well, first of all, you should use the string.match method, for finding partial names.. and secondly, check the keyword with a string.lower method, so that you don't have to put every combination of the word(:
local Player = game.Players.LocalPlayer Player.Chatted:connect(function(Text) if Text:sub(1,4):lower() == "kill" then local plrKey = Text:sub(6):lower() for i,v in pairs(game.Players:GetPlayers()) do if v.Name:lower():match(plrKey) then v.Character:BreakJoints() end end end end)