Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I fix this command in my Admin script?

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

✓ Accepted answer

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

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

2 comments

0

So I was doing it correctly, but I was coding it wrong?

0

You just used the string library instead of the actual string message. So, yeah, you were kinda doing it right.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.