I am not too familiar with string.sub(), but format would be: !report player reason (in this case). I appreciate any help ^^
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Msg)
if Msg:sub(1, 8):lower() == "!report " then
local Target = Msg:sub(9)
if Target == "" then
return
end
for k,v in pairs(Players:GetPlayers()) do
if v.Name:sub(1, #Target):lower() == Target:lower() then
print(v.Name)
else
print("No name")
end
break
end
end
end)
end)
string.sub() returns a string, and in your case, you are trying to use it as a table. Instead of doing #Target, instead do Target:len(), which will return the amount of letters in a string.
It’s possible you’re looking for string.split, it’s at the bottom of the page I linked. The way it works (and why it will be useful to you) is it will split a string based on whatever separator you pass in, and put all of the substrings into a table:
Instead of using string.sub, I’d highly suggest you use the recently added string.splt to get a more concise table of arguments.
game:GetService('Players').PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
local splits = string.split(msg," ")
if splits[1] == "!report" then
local player
local reason
for i,v in next, 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)
end
end)
end)
I don’t understand your motives of spoonfeeding @Syclya code that they should be able to figure out how to write themselves easily enough. Spoonfeeding is not a good method of teaching, and you should try to refrain from doing it.
There may be 100 ways to teach and learn, but spoonfeeding code is not one. You learn nothing from getting spoonfed code, and frankly, you should already have your solution based on prior posts. If you’d like to speak with me more about this, I suggest Direct Messaging me.
I’ve edited my post to show what it should look like using string.split.
Feel free to mark it as the solution if you wish!
In response to you, spoonfeeding is one of the many ways someone learns. You are allowed to input your opinion that spoonfeeding should not be used to teach, but as bolded it is your opinion. I myself learned most of what I can do because I had people able to help me, people that were more knowledgeable than me in the field and were enlightened to help me become better so that I can, in turn, help others when needed. Thanks for coming to my ted talk.
The print function automatically tostrings every value, otherwise it’s impossible to display (in a readable format, I mean). tostring(player) will be equivalent to player.Name.
I’ve been scripting for a few years, but that was honestly new knowledge for me. Haven’t messed around much with print() unless when it comes to debugging. Thank you! ^^
game:GetService('Players').PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
local splits = string.split(msg, " ")
if splits[1] == "!report" 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 not player then
return
end
if not reason then
return
end
local Data = {
["content"] = "Player **" .. tostring(player) .. "** has been reported by **" .. Player.Name .. "** with reason: ``` " .. tostring(reason) .. "```"
}
Data = http:JSONEncode(Data)
http:PostAsync("not showing :p", Data)
Cooldown[Player.UserId] = Player.UserId
Event:FireClient(Player, player, reason, "SUCCESS")
wait(60)
Cooldown[Player.UserId] = nil
end
end)
end)
When only typying !report, this happens and I can’t see why:
[ServerScriptService.Report tracker:26: attempt to get length of field ‘?’ (a nil value)