Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does this script not work anymore all the sudden?

Asked by
Jxyzxrr 13
5 years ago
Edited 5 years ago

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.

0
Please put in Block Code DuckyRobIox 280 — 5y
0
Also what is it about, a Dev access door? DuckyRobIox 280 — 5y
0
i am really getting pissed when people say "Please put in Block Code" when you cant paste it in block code, and it obviously is a script that kicks a player if they are not a developer. Jesus christ, no offense but are you a scripter at all? Did you look at the script? Jxyzxrr 13 — 5y
0
is this a server or localscript? Theroofypidgeot 21 — 5y
View all comments (4 more)
0
is the problem that it doesn't do anything or that it kicks you even though you're a developer? Theroofypidgeot 21 — 5y
0
it kicks me, but im a dev Jxyzxrr 13 — 5y
0
Yes, that's becaucause if you're not the first name in the "devs" table, the for loop will keep you. You now gave it the instructions to immediately kick somebody if their name doesn't mate up with the first string in the devs table, so that's where your problem is. Theroofypidgeot 21 — 5y
0
@Jxyzxrr You can actually paste your code in Block Code, just use the Block Code button at the top of the editor, it looks like "<>" MegaManSam1 207 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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.

local Devs = {"Ashley_Phantom", "ededed"}
local Players = game:GetService("Players")
Players.PlayerAdded:connect(function(plr)
local allowed = false
for i = 1,#Devs do
if plr.Name == Devs[i] then
allowed = true
end
end
if allowed == false then
plr:Kick("Not a developer: Dev access only.")
end
end)
Ad
Log in to vote
0
Answered by 5 years ago

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:

local Devs = {"Player1", "Jxyzxrr"}
local Players = game:GetService("Players")
local kickPlayer = true -- this will be set to false if the player is a dev
Players.PlayerAdded:Connect(function(player)
    for i = 1, #Devs do
        if player.Name == Devs[i] then
            kickPlayer = false -- player is a dev
        end
    end
    if kickPlayer == true then
        player:Kick("Not a developer: Dev access only.")
    end
end)

Hope this helps!

Answer this question