Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does it print "Works!" when the int value doesn't equal my UserId?

So basically I have a folder in replicatedstorage with a folder called developers in it and inside that two int values with 0.

devs = game.ReplicatedStorage.Admins.Developers
owners = game.ReplicatedStorage.Admins.Owners
admins = game.ReplicatedStorage.Admins.Admins
mods = game.ReplicatedStorage.Admins.Mods
prefix = ":"

function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end
 
function onChatted(message, player)
	for i,v in pairs(devs:GetChildren()) do
    	if message:sub(1, 2) == prefix.."M" or prefix.."m" and player.UserId == v.Value then
			print("Works!")
    	end		
	end
end
 
 
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player) end)
end)

The problem is it shouldn't print "Works!" if the value of the int ~= my userid.

1 answer

✓ Accepted answer

Your problem being is that in line 17 you wrote the following:

if message:sub(1, 2) == prefix.."M" or prefix.."m" and player.UserId == v.Value then

Your first if is OK, so that will work.

The second part (prefix.."m") isn't though.

You must clearly define it as lua will not understand what needs to be what, so it will automatically say "true"

It should be like this:

if message:sub(1, 2) == prefix.."M" or message:sub(1,2) == prefix.."m" and player.UserId == v.Value then

And there you go!

Also, your script is clustered, you could easily just change it to this:

if message:sub(1, 2):lower() == prefix:lower().."m" and player.UserId == v.Value then

And there you go.

This discussion is preserved as it was. New answers, comments, and votes are closed.