Hello! I’m relatively new to scripting, and I made an anticheat that detects if a hacker were to change their health, speed, jump, insert gyro, etc.
the only issue is that I need to whitelist a group of admins for the game
I made a list of usernames (not user id) of admins, here is an example
local admins = {
"User1";
"User2";
"User3"
}
I am lost as to how I would actually grab that list of players, (I don’t know the variables for that), the only solution I tried that worked, only worked for one person.
That solution was this
if Player.UserId ~= 00000000 then
-- script here
end
end
That’s just one person, not a group of people, as you can probably tell, I am very new to scripting xD! I am completely open to critiquing and information to improve.
I appreciate anyone who tries to help!
And by the way, when the script detects someone is hacking, it uses Player:Kick(“reason”), if that helps.
If you need more information on the code I am using, or if I explained something wrong, please tell me, I will respond as soon as possible.
local admins = {
["User1"] = true,
["User2"] = true,
["User3"] = true,
}
game.Players.PlayerAdded:Connect(function(plr)
if admins[plr.Name] then
-- code here
end
end)
So, in my script to detect humanoid value changes I created max/min values like this:
local MaxSpeed = 16
local MinSpeed = 16
--(repeat for other values)
Then to detect it, I wrote if statements, like this.
while wait(.05) do
if Humanoid.WalkSpeed > MaxSpeed then return kick() end
if Humanoid.WalkSpeed < MinSpeed then return kick() end
--(repeat for other value checks)
Now, on its own, this works, but of course I can’t exclude any users from it.
When I inserted your code it looked something like this:
local MaxSpeed = 16
local MinSpeed = 16
--other values would be here as well
local admins = {
["User1"] = true,
["User2"] = true,
["User3"] = true,
}
game.Players.PlayerAdded:Connect(function(plr)
if admins[plr.Name] then
while wait(.05) do
if Humanoid.WalkSpeed > MaxSpeed then return kick() end
if Humanoid.WalkSpeed < MinSpeed then return kick() end
-- other checks would go here
end
end
end)
I am probably forgetting to include something, sorry for the trouble.
there are no errors in the output either.
If you can help me understand what I need to do, that would be great!
It would be like this, since you want admins to be whitelisted from anti cheat…
local MaxSpeed = 16
local MinSpeed = 16
--other values would be here as well
local admins = {
["User1"] = true,
["User2"] = true,
["User3"] = true,
}
game.Players.PlayerAdded:Connect(function(plr)
if not admins[plr.Name] then
while wait(.05) do
if Humanoid.WalkSpeed > MaxSpeed then return plr:Kick() end
if Humanoid.WalkSpeed < MinSpeed then return plr:Kick() end
-- other checks would go here
end
else
print("Whitelisted player!")
end
end)
To check if a player is in the admin list, you can use a for loop to iterate through the list of admin usernames and check if the current player’s name matches any of them. Here’s an example code snippet:
local admins = {
"User1",
"User2",
"User3"
}
function checkAdmin(player)
for i = 1, #admins do
if player.Name == admins[i] then
return true
end
end
return false
end
-- Example usage in your anticheat script
if not checkAdmin(Player) then
Player:Kick("Cheating detected!")
end
In this code, we define the list of admin usernames in the same format as you did in your example. We then create a function called “checkAdmin” that takes in a player object as an argument. The function iterates through the admin list using a for loop and checks if the player’s name matches any of the admin usernames. If a match is found, the function returns true, indicating that the player is an admin. If no match is found, the function returns false.
You can then use this function in your anticheat script to check if a player is an admin before kicking them if cheating is detected.
Thanks to both of you for helping me! I appreciate it.
The check admin for loop worked, I really appreciate your explanation! I understand how that code works, and I also have a better understanding on how for loops work too, I really do appreciate it guys!