Hey everyone, I’m trying to make a command but it doesn’t work. No errors in output whatsoever. Please help me, it’s really appreciated.
Code:
local groupId = 123456
local adminRank = 10
function onChatted(msg, speaker)
if speaker:GetRankInGroup(groupId) >= adminRank then
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!rules" then
print("testing")
else
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
Hey, I don’t see anything wrong in the code. But prints are great for debugging, you should put prints after every if in the function, and see where it stops printing.
That’s what I usually do when I don’t see an error but something doesn’t work.
You can add a print before every if, after the OnChatted line, if it prints, you atleast know the function does run.
function onChatted(msg, speaker)
print("function runs")
If that’s printed, then you can move to the next one.
It says I’m not enough high rank, though I am rank 17 if I understood correctly.
local groupId = 123456
local adminRank = 9
function onChatted(msg, speaker)
print("function runs")
if speaker:GetRankInGroup(groupId) >= adminRank then
print("if speaker get rank if print here")
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == "!rules" then
print("testing")
else
print("else thing after priint testing")
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)
Yes, I do have the group id set correctly but just changed it.
So as you can see, it runs, but reaches the else thing, which means the message is not exactly !rules
So I think I know what your problem is, chat messages include a lot of spacing since the player name shows before them. So instead of using == , use string.find(“!rules”, msg), I am not sure if there’s a thing like replace, here’s the string library:
local groupId = 123456
local adminRank = 9
function onChatted(msg, speaker)
print("function runs")
if speaker:GetRankInGroup(groupId) >= adminRank then
print("if speaker get rank if print here")
local source = string.lower(speaker.Name)
msg = string.lower(msg)
if msg == string.find("!rules", msg) then
print("testing")
else
print("else thing after priint testing")
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:connect(function(msg)onChatted(msg, player) end)
end)