local Devs = {“Jxyzxrr”, “id”}
local Players = game:GetService(“Players”)
Players.PlayerAdded:connect(function(plr)
for i = 1,#Devs do
if plr.Name ~= Devs[i] then
plr:Kick(“Not a developer: Dev access only.”)
end
end
end)
Script above does not work anymore, I do not know why.
It’s stored in ServerScriptService.
Hey, I fixed your issue, the issue was that if your array has more than one element, the for loop will go through it and check it too, if it happens to be another user, it'll still kick you even if you are in the array.
01 | local Devs = { "Ashley_Phantom" , "ededed" } |
02 | local Players = game:GetService( "Players" ) |
03 | Players.PlayerAdded:connect( function (plr) |
04 | local allowed = false |
05 | for i = 1 ,#Devs do |
06 | if plr.Name = = Devs [ i ] then |
07 | allowed = true |
08 | end |
09 | end |
10 | if allowed = = false then |
11 | plr:Kick( "Not a developer: Dev access only." ) |
12 | end |
13 | end ) |
The reason this script breaks is because when you run your for loop, if ANY player is not in the table, you get kicked. This being said, you have both yourself and “id” in your table, so you don’t get kicked after the first loop, but because your name isn’t “id” as well, you get kicked on the second one. There is a simple fix to this, just make another variable that defines whether the player should be kicked after the loop runs. Example:
01 | local Devs = { "Player1" , "Jxyzxrr" } |
02 | local Players = game:GetService( "Players" ) |
03 | local kickPlayer = true -- this will be set to false if the player is a dev |
04 | Players.PlayerAdded:Connect( function (player) |
05 | for i = 1 , #Devs do |
06 | if player.Name = = Devs [ i ] then |
07 | kickPlayer = false -- player is a dev |
08 | end |
09 | end |
10 | if kickPlayer = = true then |
11 | player:Kick( "Not a developer: Dev access only." ) |
12 | end |
13 | end ) |
Hope this helps!