game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(player, message, recipient)
message = string.lower(message)
local splitString = message:split(" ")
local cmdName = splitString[1]
if commands[cmdName] then
local arguements = {}
for i = 2, #splitString, 1 do
table.insert(arguements,splitString[i])
end
commands[cmdName](player, arguements)
end
end)
end)
This is the error message: Invalid argument #1 to ‘lower’ (string expected, got nil)
Its for the line message = string.lower(message)
as if the chatted function isnt identifying ive typed anything. Tried everything I can so far cant find anything to fix it.
1 Like
try this?
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(player, message, recipient)
if type(message) == "string" then
local message = string.lower(message)
local splitString = message:split(" ")
local cmdName = splitString[1]
if commands[cmdName] then
local arguements = {}
for i = 2, #splitString, 1 do
table.insert(arguements,splitString[i])
end
commands[cmdName](player, arguements)
end
end
end)
end)
This won’t work, first of all the only parameter of player.Chatted is the message, there are no others. Secondly,
Is unnecessary because the message will always be a string.
As for @La_Conqueror remove the player and recipient parameters, the code should be:
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local message = string.lower(message)
local splitString = message:split(" ")
local cmdName = splitString[1]
if commands[cmdName] then
local arguements = {}
for i = 2, #splitString, 1 do
table.insert(arguements,splitString[i])
end
commands[cmdName](player, arguements)
end
end)
end)
I don’t know where you got those parameters from
Thank you so much, this really helps.
1 Like