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

:lower() doesn't work for a command I'm making. How do I fix this?

As long as I know, using :lower() can make us use both caps and lower

I tried making a command like if message == ";kick " .. playername:lower() then but when I typed that in roblox's chat as caps lock it doesn't fires the if statement

How can I fix this?

2 comments

0

It’s because you are not calling lower on the message, so you are still comparing capitals to lower case.

0

oh thanks

2 answers

You should convert the command to lowercase first, and compare if the first 6 letters is ";kick ". If yes, then you can get the player by doing string.sub(lowercaseCommand, string.len(kickCommand) + 1, string.len(lowercaseCommand). Here's a concept:

local lowercaseCommand = string.lower(message) -- replace message of your chatted function parameter
local kickCommand = ";kick " -- Remember to put a space so you can easily separate command and player and make this FULLY LOWERCASE

if string.sub(lowercaseCommand, 1, string.len(kickCommand)) == kickCommand then
	local playerInCommand = string.sub(message, string.len(kickCommand) + 1, string.len(lowercaseCommand)) -- Get the player, for example ";kick Xapelize" from the length of kickCommand plus 1 is 7, so starting from X to the last length of message (since it returns the correct capitalization of player) is e, so it returns Xapelize
	local player = game:GetService("Players"):FindFirstChild(playerInCommand) -- Find the player, FindFirstChild detect if something exists, if not, it returns nil instead of error

	if player then -- If player exists
		player:Kick("You have been kicked") -- Kick the player
	end
end

This is a concept, you need to code the rest yourself though

3 comments

0

if you are still confused then ill code the whole thing for you, but try this as a challenge

0

oh by the way, you can use string.split(message, " "). the 2nd index is player and the rest after kickCommand length + player name length + 1 (because space) letters is the reason

0

i might be explaining stuffs trash because yeah i dont know

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