How to make the text string lower in this script

local Commands = {
    kick = "kick "
}

local Prefix = "!"

game.Players.PlayerAdded:Connect(function(players)
    players.Chatted:Connect(function(message)
        for i,v in pairs(Owner) do 
            if v == players.UserId then
                for i,v in pairs(game.Players:GetChildren()) do
                    if message == Prefix..Commands.kick..v.Name then
                        v:Kick("Test")
                    end
                end
            end
        end
    end)
end)

Any help is appreciated

1 Like

You can use string:lower(), you can use the “%l” special key to play with it and turn your string into low cases.

1 Like

this error occurs

ServerScriptService.ChatCommands:197: invalid argument #1 to 'lower' (string expected, got table)

that means ur “string” is a table and not a string

1 Like

Try this -

 if message == Prefix..string.lower(Commands.kick)..v.Name then

If you want your entire message to be low case -

if string.lower(message) == Prefix..Commands.kick..v.Name then
1 Like

You cannot use :lower() nor string.lower() on a table. Could you please give more information about the error (the line, the error in the output, etc)

1 Like

pretty sure he wants

if string.lower(message) == Prefix..Commands.kick..v.Name then
1 Like

I have made a module for chat commands go check this out!

Well, his post wasnt that clear, I hope he elaborates a bit, because you can take that into several paths.

2 Likes

hmm yes but I like to view by the perspective of the questioner. But I respect the way you think!

1 Like

well it does not have an error and it doesnt run

hmm then maybe its with how you typed it

1 Like

well i printed the command this it it

print(Prefix..Commands.kick..v.Name)
!kick Paysallday44

but when i type it in caps it doesnt run

wait hold on ill send you a working script.

1 Like

here you go : D

local function autofill(abbreviation) -- autofills player name
	for i,v in ipairs(game:GetService("Players"):GetPlayers()) do
		if v.Name:lower():sub(1,abbreviation:len()) == abbreviation:lower() then
			return v
		end
	end
end

local Commands = { -- commands
	kick = "kick"
}

local prefix = "!" -- prefix

game.Players.PlayerAdded:Connect(function(plr) -- getplayer
	plr.Chatted:Connect(function(message) -- chatted
		local split = string.split(message," ") -- splits the message by spaces
		if string.lower(split[1]) == prefix..Commands.kick then -- checks for command
			local player = autofill(split[2]) -- gets player
			if player then
				local reason = split[3] -- reason
				if not reason then reason = "Unknown" end -- if there isnt any reason the reason becomes Unknown... literally
				player:Kick(reason) -- kick
			end
		end
	end)
end)

And yea this works 100%

1 Like

Yeah this script actually works appreciate it

yea welcome and this also has a reason and autofill if you didnt know : )

1 Like