local Ranks = {"OR-1", "OR-2", "OR-3"}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(content)
local chatcontent = content:lower()
if plr.Name == "ByGermanKnight" then
if string.sub(content, 0, 1) <= "/" and string.sub(content, 2, 5) == "rank" then
for _, v in pairs(Ranks) do
if v == string.sub(content, 7, 10) then
print("HEY")
end
end
end
end
end)
end)
Can someone explain me why this script doesn’t work? It gives me no error, nothing.
You can’t use <= on a string. But that would throw an error, so clearly it’s not getting that far. How far does it get? Throw some prints in there so you an see what line it stops on.
1 Like
I know that I can’t use that, but (I don’t know why) it works. If I won’t use that, it wouldn’t work.
I don’t know what you mean with “Throw some prints in there so you an see what line it stops on”.
He meant to print out random values through the code, step by step. For example:
if string.sub(content, 0, 1) <= "/" and string.sub(content, 2, 5) == "rank" then
print("WORKS TILL HERE")
Which means that if “WORKS TILL HERE” isn’t printed in the output, there is a problem with line before that. I also agree with @JarodOfOrbiter. string.sub doesn’t transform a string into a number value, so you can’t use mathematical expressions on it. Why don’t you try replacing <= with ==?
I don’t know what is wrong with Roblox, but I think its glitched because sometimes I works and sometimes it doesnt. I changed the code also a little bit and now the Chat Windows disappears for some reason and there is only this script with this code in the ServerScriptService.
New Code:
local Ranks = {"OR-1", "OR-2", "OR-3"}
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(content)
local chatcontent = content:lower()
if plr.Name == "ByGermanKnight" then
if string.sub(content, 0, 1) == "/" and string.sub(content, 2, 5) == "rank" then
for i, v in pairs(Ranks) do
if v == string.sub(content, 7, 10) then
print("v is exualtz to!")
end
end
end
end
end)
end)
Oh, well, you transformed all of your letters in a message to lower case. You can’t compare that with upper case in table.
What about:
local Ranks = {"or-1", "or-2", "or-3"}
1 Like
Forget the lower. I tested something with that. Its useless atm. I also tried it with Localplayer in a Localscript and now it works.
Alright, great, however, be sure to keep the game as safe from exploiters as possible, so rather use server scripts when it comes to ATM-s. If I were you, I’d try replacing and if it works, keep it that way.
1 Like
Okay, thank you for your help.
1 Like