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

Admin commands are not working properly..?

No errors or anything, no clue whats wrong with this.

local owner = {game.CreatorId} -- add UserIds in this format 'game.CreatorId, 39493, 304034' etc..
local admin = {} -- add UserIds like above.

local Int = Instance.new('IntValue')

game.Players.PlayerAdded:connect(function(plr)
	for _,v in pairs(owner or admin) do
		if plr.UserId == v then
			print('hi')
		
			
		
		end
	end
end)

2 comments

0

connect is deprecated. Use Connect.

0

Thunder, its deprecated which means it isn't being updated. 'connect' still works as of current.

2 answers

✓ Accepted answer

Eh, here let's start over, your script doesn't seem correct but your on to something.

First let's setup the variables and the event.

local owner = {game.CreatorId}
local admin = {}

game.Players.PlayerAdded:connect(function(plr)
	
end)

Next let's create a variable inside the event and then check through each id to see if the plr's id is in one of the tables

local owner = {game.CreatorId}
local admin = {}

game.Players.PlayerAdded:connect(function(plr)
	local isin = false
	for _,v in pairs(owner) do
		if v==plr.UserId then
			isin=true
			break
		end
	end
	if isin==false then
		for _,v in pairs(admin) do
			if v==plr.UserId then
				isin=true
				break
			end
		end
	end
	if isin==true then
		print("he's in")
	end
end)

1 comment

0

Thank you.

Expanding on Danz script; you can also use a dictionary array, which would allow you to check the table without running a for loop each time.

local admin = { 
	['azarth'] = {creator = true, id = 312625920};
	['danzlua'] = {creator = false, id = 12345};
}

-- Note that CreatorId will be 0 in studio.

local function player_joined(plr)
	local index = admin[plr.Name:lower()]
    if index then 
		if index.id == plr.UserId then 
			if index.creator then 
				print( string.format("%s is the creator", plr.Name))
			else
				print( string.format("%s is an admin", plr.Name))
			end
		else
			print( string.format("%s is a(n) %s, but the UserId didn't match.", plr.Name, index.creator and 'creator' or 'admin'))
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	player_joined(plr)
end)

-- Catches the players that joined before PlayerAdded connected.
for i,v in pairs(game.Players:GetPlayers()) do
	player_joined(v)
end

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