This is because there’s only one member of splits. When you do #splits[2]
, it’s checking the length of splits[2]
. When you just type !report, there’s not going to be a splits[2]
. You can fix this by checking if splits[2]
and splits[3]
exist before checking their length. For example, you could replace if splits[1] == "!report" then
with if splits[1] == "!report" and splits[2] and splits[3] then
2 Likes
Noticed that. But the script seems to have new errors everytime I test it:
game:GetService('Players').PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
local splits = string.split(msg, " ")
if splits[1] == "!report" and splits[2] and splits[3] then
if Cooldown[Player.UserId] then
Event:FireClient(Player, "", "", "COOLDOWN")
return
end
local player
local reason
for i, v in pairs(game:GetService('Players'):GetPlayers()) do
if string.sub(v.Name, 1, #splits[2]):lower() == splits[2]:lower() then
player = v
table.remove(splits, 2)
table.remove(splits, 1)
reason = table.concat(splits, " ")
end
end
--print(player, '|',reason)
if tostring(player) == Player.Name then
Event:FireClient(Player, "", "", "SELF_REPORT")
return
end
if player == nil then
Event:FireClient(Player, "", "", "NO_PLAYER")
return
end
if reason == nil then
return
end
local Data = {
["content"] = "Player **" .. tostring(player) .. "** has been reported by **" .. Player.Name .. "** with reason: ``` " .. tostring(reason) .. "``` @everyone"
}
Data = http:JSONEncode(Data)
http:PostAsync("", Data)
Cooldown[Player.UserId] = Player.UserId
Event:FireClient(Player, tostring(player), tostring(reason), "SUCCESS")
wait(60)
Cooldown[Player.UserId] = nil
end
end)
end)
^ when you try to report yourself.