How I make a Admin Script? Part 2

Hi there, before watching this topic, please see part 1 here: How I make a Admin Script?

I wanted to make a admin script but i failed and i need more help in this one.

The script i used:

local admins = {
	require(script.Parent.Settings).Ranks
}

function IsAdmin(player)
	for _,Admin in pairs(admins) do
		if Admin:lower() == player:lower() then
			return true
		end
	end
	return false
end

game.Players.PlayerAdded:Connect(function(Player)
	if IsAdmin(Player) then
		local ui = script.AdminGUI:Clone()
		ui.Parent = Player.PlayerGui
	elseif script.AdminGUI:Clone().Parent == Player.PlayerGui and not IsAdmin(Player) then
		Player:Kick("Reason: \n Exploiting to AdminScreen. \n Kicked By System")
	end
end)

Someone told to me that the elseif part is wrong and im trying to correct that part.
If you want to help, please tell in the comments your opinions or scripts!

4 Likes

Does it use Names or UserIds
since

here u are just comparing Player instance with a string?

do player.Name:lower()

1 Like

Well what is the problem?

chars

1 Like

Names can be changed
UserIDs cant be changed

1 Like

The problem is:
the elseif part

Yes but like what is happening? Does any player get kicked all the time?

No. If he gets a admingui, the script will have to kick him but i dont know how to do that

Is it not kicking the player or something?

there 2 choices, kicking or removing the GUI

Okay, but what is the script not doing that you want it to, or doing that you don’t want it to?

im trying to figure out the code to do it but im starter :crying_cat_face:

Well you are checking if UI is parented to a function, which won’t work.

Instead, you could return players who are admins from the IsAdmin(player) function, and in the elseif part do:

elseif ui.Parent == Player.PlayerGui and not Admin then
	Player:Kick("Reason: \n Exploiting to AdminScreen. \n Kicked By System")
end



is showing a error on the script that blue

Have you returned Admin from the function?

Also changed ui.Parent to script.AdminGUI:Clone().Parent that was my bad.

but cant i make

local ui = script.AdminGUI:Clone()

elseif ui.Parent

?

also i will change the name to UserID because userids cant be changed
but i need to change the function to work but do i need to still use string.lower?

Yes, I made a mistake because my square brain saw local ui = script.AdminGUI:Clone() and didn’t see script.AdminGUI:Clone().Parent. I said to change that to the latter in my last post.

UserIDs aren’t strings, so no. string.lower is not required.

1 Like

Using Local will make the thing public to the script example:

local message = "Hi"
print(message)

Actually using local will keep something locally, such as inside a function or loop. Example:

local value = 90
function dosomething()
	local functionvalue = 45
	for _ = 1, 100 do
		functionvalue = functionvalue + value
	end
end