Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this script not work anymore all the sudden?

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.

8 comments

0

Please put in Block Code

0

Also what is it about, a Dev access door?

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?

0

is this a server or localscript?

0

is the problem that it doesn't do anything or that it kicks you even though you're a developer?

0

it kicks me, but im a dev

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.

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 "<>"

2 answers

✓ Accepted answer

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)

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.