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

How can I fix this command in my Admin script?

Asked by 10 years ago

The script is supposed to kill a player's Character, I've tried so many times to fix it but it still doesn't work, here is the script command;

if string.lower(string.sub(1,5),msg)=="kill/"
findplayer=game:service("Players"):FindFirstChild(string.sub(4))
if findplayer then
findplayer.Character:BreakJoints()
end end

What am I doing wrong?

3 answers

Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
10 years ago

I believe your error is on line 2. You had string.sub(4) which would return 'l/playername'. If you change that 4 to a 6, it'll return 'playername' instead.

Also, the layout for your string.sub was incorrect. It should be string.sub("Text",#,#) )

if string.lower(string.sub(msg, 1 , 5)) =="kill/"
    findplayer = game.Players:FindFirstChild(string.sub(msg, 6))
    if findplayer then
        findplayer.Character:BreakJoints()
    end 
end
Ad
Log in to vote
0
Answered by
brianush1 235 Moderation Voter
10 years ago

Here you go, a working and tested code:

if msg:lower():sub(1,5)=="kill/"
findplayer=game:service("Players"):FindFirstChild(msg:sub(6)) -- You can't get the characters of the "string" library. It's not a text.
if findplayer then
findplayer.Character:BreakJoints()
end end
0
So I was doing it correctly, but I was coding it wrong? TheeDeathCaster 2368 — 10y
0
You just used the string library instead of the actual string message. So, yeah, you were kinda doing it right. brianush1 235 — 10y
Log in to vote
-1
Answered by 10 years ago
if string.lower(string.sub(1,5),msg)=="kill/"
findplayer=game.Players:FindFirstChild(string.sub(4))--no need to use getservice just use game.Players
if findplayer then
findplayer.Character:BreakJoints()
end end

Answer this question