local Players = game:GetService("Players")
local PlayersChildren = Players:GetChildren()
local Http = game:GetService("HttpService")
local Webhook = ...
game.Players.PlayerAdded:Connect(function(reportingPlayer)
reportingPlayer.Chatted:Connect(function(msg, recipient)
msg = string.lower(msg)
local arguments = msg:split(" ")
local command = arguments[1]
local subject = arguments[2]
local reason = arguments[3]
local reportedPlayer = Players:FindFirstChild(tostring(subject))
if reportedPlayer then
local PlrName = reportedPlayer.Name
if string.sub(command, 1, 8) == "-report " and string.sub(msg, 9) == string.lower(PlrName) then
local data =
{
["contents"] = "",
["username"] = reportingPlayer.Name .. " - "..reportingPlayer.UserId,
["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..reportingPlayer.UserId,
["embeds"] = {{
["title"]= reportingPlayer.Name.." has reported "..reportedPlayer.Name.." for exploiting in a server of "..#PlayersChildren.." players",
["url"] = "https://www.roblox.com/users/profile/"..reportingPlayer.UserId,
["description"] = "Reason - "..reason,
["type"]= "rich",
}}
}
print("reported "..reportedPlayer.Name)
Http:PostAsync(Webhook,Http:JSONEncode(data))
end
else
warn("Player not found")
end
end)
end)
Do you still get the same error or did a new one show up? Since it’s impossible for it to still produce that error unless msg was nil, in which case the string.lower call would’ve errored
It shouldn’t return nil as I have just used the split method a few times in the chat to make admin commands in my next video which will be today at 12:00pm est btw if you want to see how I split it. I don’t know if it will help but if it still doesn’t work then maybe try it?
The issue was that the OP was checking if the return of msg:split(" ") contained a space (which is an impossible scenario), and also due to the string.lower part the code would fail to grab the player if they had an uppercase letter in their name. Also the reason part supported only 1 word.
Here is the fixed code:
local Players = game:GetService("Players")
local PlayersChildren = Players:GetChildren()
local Http = game:GetService("HttpService")
local Webhook = ...
game.Players.PlayerAdded:Connect(function(reportingPlayer)
reportingPlayer.Chatted:Connect(function(msg, recipient)
local arguments = msg:split(" ")
if arguments[1] then
local command = table.remove(arguments, 1)
if command == "-report" then
local subject = table.remove(arguments, 1)
local reason = table.concat(arguments, " ")
local reportedPlayer = Players:FindFirstChild(subject)
if reportedPlayer then
local PlrName = reportedPlayer.Name
local data =
{
["contents"] = "",
["username"] = reportingPlayer.Name .. " - "..reportingPlayer.UserId,
["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..reportingPlayer.UserId,
["embeds"] = {{
["title"]= reportingPlayer.Name.." has reported "..reportedPlayer.Name.." for exploiting in a server of "..#PlayersChildren.." players",
["url"] = "https://www.roblox.com/users/profile/"..reportingPlayer.UserId,
["description"] = "Reason - "..reason,
["type"]= "rich",
}}
}
print("reported "..reportedPlayer.Name)
Http:PostAsync(Webhook,Http:JSONEncode(data))
else
warn("Player not found")
end
end
end
end)
end)