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

Can someone help me with a kill/playername script?

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

I know how to do all but one thing.

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        if msg:sub(1,5) == "kill/" then
            local killedPlr = game.Players:FindFirstChild(msg:sub(6))
            if killedPlr then
                killedPlr.Character.Humanoid.Health = 0
            end
        end 
    end)
end)

The only thing I do not know how to do is make it so that it is possible to abbreviate the player's name. I would appreciate help with this.

2 answers

Log in to vote
1
Answered by
Destrings 406 Moderation Voter
10 years ago

Given an array of strings, we can get the element that matches

strings = {"lombardo2", "applepie", "pawner123", "pizzadude24", "Apatheia"}

function getStringThatMatch(t, p)
    for k, v in next, t do
        if v:match("^"..p) then
            return v
        end
    end
    return nil
end

print(getStringThatMatch(strings, "lom"), getStringThatMatch(strings, "123"))
0
That does work, and I appreciate you help, but how could I make it so that "lom" would work the same, but "123" would return nil. This is so that if someone said "kill/p", it wouldn't just kill the first person with p in their name. It would kill the person who's name starts with p. Perci1 4988 — 10y
0
Edited to work like that Destrings 406 — 10y
0
Thank you! Perci1 4988 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

If you mean like Admin Commands, then;

--Kind of edited your script
local Admins = {"Perci1","bestfriend","friend"} --Add names here

game.Players.PlayerAdded:connect(function(plr) --Player Added event
for i,v in pairs(Admins)do --For loop for Admins
if plr.Name:lower()==v:lower()then --If plr's Name matches to Admins then
plr.Chatted:connect(function(msg) --Player chatted
if msg:sub(1,5) == "kill/" then --If the command starts will 'kill/' then
local killedPlr = game.Players:GetChildren() --Gets the Children of game.Players
for i, v in pairs(killedPlr)do --For look for game.Players
if v:IsA("Player")then --If is a Player
if v and v.Name:lower()==msg:sub(6) and v.Character then --If player, player's Character exists, and player's Name matches then
v.Character:BreakJoints() --Kills player
end end end end end)end end end) --All the ends

I hope this helped!

Answer this question