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.
01 | local Player = game.Players.LocalPlayer |
02 | Player.Chatted:connect( function (Text) |
03 | if string.sub(Text, 1 , 4 ) = = "Kill" or "kill" or "KILL" then |
04 | for i,v in pairs (game.Players:GetChildren()) do |
05 | for i = 7 , tonumber (string.len(v.Name)), 1 do |
06 | local Length = tonumber (string.len(Player.Name)) |
07 | if string.sub(Text, 6 ,i) = = string.sub(v.Name, 1 ,Length-(i- 6 )) then |
08 | --I think its something above and between[ ] |
09 | v.Character.Humanoid.Health = 0 |
10 | end |
11 | end |
12 | end |
13 | end |
14 | end ) |
15 |
16 | --[["Kill tuma" |
17 | 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(:
01 | local Player = game.Players.LocalPlayer |
02 |
03 | Player.Chatted:connect( function (Text) |
04 | if Text:sub( 1 , 4 ):lower() = = "kill" then |
05 | local plrKey = Text:sub( 6 ):lower() |
06 | for i,v in pairs (game.Players:GetPlayers()) do |
07 | if v.Name:lower():match(plrKey) then |
08 | v.Character:BreakJoints() |
09 | end |
10 | end |
11 | end |
12 | end ) |