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

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

Asked by 3 years ago

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?

0
It’s because you are not calling lower on the message, so you are still comparing capitals to lower case. Benbebop 1049 — 3y
0
oh thanks WINDOWS10XPRO 438 — 3y

2 answers

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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

0
if you are still confused then ill code the whole thing for you, but try this as a challenge Xapelize 2658 — 3y
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 Xapelize 2658 — 3y
0
i might be explaining stuffs trash because yeah i dont know Xapelize 2658 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

i just have to make message:lower()

Answer this question