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
6 years ago
Edited 6 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 — 6y
0
Also what is it about, a Dev access door? DuckyRobIox 280 — 6y
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 — 6y
0
is this a server or localscript? Theroofypidgeot 21 — 6y
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 — 6y
0
it kicks me, but im a dev Jxyzxrr 13 — 6y
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 — 6y
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 — 6y

2 answers

Log in to vote
1
Answered by 6 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.

01local Devs = {"Ashley_Phantom", "ededed"}
02local Players = game:GetService("Players")
03Players.PlayerAdded:connect(function(plr)
04local allowed = false
05for i = 1,#Devs do
06if plr.Name == Devs[i] then
07allowed = true
08end
09end
10if allowed == false then
11plr:Kick("Not a developer: Dev access only.")
12end
13end)
Ad
Log in to vote
0
Answered by 6 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:

01local Devs = {"Player1", "Jxyzxrr"}
02local Players = game:GetService("Players")
03local kickPlayer = true -- this will be set to false if the player is a dev
04Players.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
13end)

Hope this helps!

Answer this question