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

help with string manipulation?

i dont focus that much on string manipulation, but I want to make a kick command though when i was testing around with string.sub it doesnt work for some reason:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message == string.sub(":kick ", 1, 6) then
			print("lol")
		end
	end)
end)

im not asking for a script of a entire kick command, but i just want a idea of it

1 answer

✓ Accepted answer

You should definitely use:

string.match(a1, a2)

This will definitely give you the results you need.

Example:

if string.match(message, ":kick ") then

	print('Someone was kicked')

	if game.Players:FindFirstChild(message:gsub(":kick ", '')) then
		
		game.Players:FindFirstChild(message:gsub(":kick ", '')):Kick()

		print(game.Players:FindFirstChild(message:gsub(":kick ", '')).Name..' was kicked')

	end

end

Why?

If it does contain that message, then it returns true, if it doesn't- return false.

a1 = string/target

a2 = string to find in target

2 comments

0

what is gsub

0

:gsub - arg1 = the message, arg2 = the text to look for inside of the message, arg3 the string to replace the text with

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