Basic Admin playerAdded not running in studio

Basic Admin just doesn’t add itself to the player, because the playerAdded function is 3,000 lines deep and won’t fire early enough for me to test in studio. I tried making this adjustment:

playerService.PlayerAdded:connect(function(Player)
		if sysTable.shuttingDown then
			Player:Kick('Basic Admin\n'..sysTable.shutdownReason)
			return
		end
		local Status,Normal = managePlayer(Player)
		if not Normal then
			addLog(sysTable.debugLogs,Status)
		end
	end)
	
--============== MY ADDITION ================================
	task.spawn(function ()
		for _, Player in pairs(playerService:GetChildren()) do
			if sysTable.shuttingDown then
				Player:Kick('Basic Admin\n'..sysTable.shutdownReason)
				return
			end
			local Status, Normal = managePlayer(Player)
			if not Normal then
				addLog(sysTable.debugLogs,Status)
			end
		end
	end)

But I still get nothing on the client side.

There is no need to do this. When the shutdown command is run, the code will kick all existing players from the server. The purpose of this check at the end is just to make sure any players that join after the shutdown command is run are kicked as well. You can see how the program handles shutdowns in Funcs.Shutdown, which is on lines 937-954.

That’s not the issue; the issue is, when i test the game in studio, the player loads before the script, meaning playerAdded wont run and the player doesnt get admin

Oh I see. Apologies for the confusion. In that case, you would want to run the same code that was inside the function connected to PlayerAdded and do something like this:

local function onPlayerAdded(Player)
	if sysTable.shuttingDown then
		Player:Kick('Basic Admin\n'..sysTable.shutdownReason)
		return
	end
	local Status,Normal = managePlayer(Player)
	if not Normal then
		addLog(sysTable.debugLogs,Status)
	end
end

playerService.PlayerAdded:Connect(onPlayerAdded)
for _, Player in next,playerService:GetPlayers() do
	onPlayerAdded(Player)
end

Additionally, If you know that the server won’t be shutdown, you can see that the only other logic inside the function is that to call managePlayer, so you can run that inside your loop.

1 Like

isn’t that basically the same code I had already made?

No, it will call the added function for all existing players when it gets there.
I’d also suggest wrapping each manual execution with task.spawn(function() end to avoid yielding.

task.spawn(function ()
		for _, Player in pairs(playerService:GetChildren()) do
			if sysTable.shuttingDown then
				Player:Kick('Basic Admin\n'..sysTable.shutdownReason)
				return
			end
			local Status, Normal = managePlayer(Player)
			if not Normal then
				addLog(sysTable.debugLogs,Status)
			end
		end
	end)

that’s what this does

Then your code must not be running at all. Try some break points or print statements to debug and get back to us.

I already tried that before, here’s what happens:
managePlayer() yields the script for a pretty long time, but eventually the entire script runs through.
However, even after the whole script runs, I end up with no admin.

So the problem must be inside of your managePlayer function. Try debugging on your own first before asking for help. And when you find that you do need help, please share all relevant code and steps taken to try to debug the problem already.

its not my script. its a public script, it works otherwise. I just need it to run on existing players. The issue is not in managePlayer()

You should reach out to the creator for support.

My mistake (once again). I did not notice since the indentation was kind of messed up. Anyway, I was not able to find any other connections to PlayerAdded so your code should work perfectly fine (however I do think that it would be better to wrap the inner part of a loop in a task.spawn if you believe that managePlayer yields. Maybe the issue is somewhere else?