Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

What is wrong with my vey simple math?

Asked by
tumadrina 179
10 years ago

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.

01local Player=game.Players.LocalPlayer
02Player.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
14end)
15 
16--[["Kill tuma"
17     123456789]]

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

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(:

01local Player = game.Players.LocalPlayer
02 
03Player.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
12end)
Ad

Answer this question