Hello! I've got a bit of a problem with my ban command script, and I've narrowed it down to this function with the help of print debugging. My issue with this is that I'm trying to make it so that moderators within the game aren't able to ban eachother. However, this doesn't seem to work.
local function banByUserID(userid) local nameofUser = game.Players:GetNameFromUserIdAsync(userid) for i,v in pairs(moderators) do if v == nameofUser then print ("Nice try. /".. nameofUser.. "/ is a moderator and can't be banned!") else -- should stop at this once has detected a moderator if bansDataStore:GetAsync("banned_"..userid,1) then print ("User ".. nameofUser.. " has already been banned!") else if nameofUser then bansDataStore:SetAsync("banned_"..userid,1) if game.Players:FindFirstChild(nameofUser) then game.Players:FindFirstChild(nameofUser):Kick(reason) end print ("User ".. nameofUser.. " has been banned!") end end end end end
It should stop at the "else" once it has detected a moderator, but it keeps going on, resulting in this and banning the moderator anyway. image showing output
The "moderator" variable is just a regular table with strings of people's usernames.