Error while using Adonis admin SetLevel function

So, I’ve been trying to use Adonis to change the level of admin once a new value is set to a hosting queue in Workspace. It does the function correctly, but I get errors when I try to use server.Admin:SetLevel(). It’s supposed to change the level of admin to CurrentHost, instead it’s erroring out.

Here is the code I’ve been using:

	SERVER PLUGINS' NAMES MUST START WITH "Server: "
	CLIENT PLUGINS' NAMES MUST START WITH "Client: "
	
	Plugins have full access to the server/client tables and most variables.
	
	You can use the MakePluginEvent to use the script instead of setting up an event.
	PlayerChatted will get chats from the custom chat and nil players. 
	PlayerJoined will fire after the player finishes initial loading
	CharacterAdded will also fire after the player is loaded, it does not use the CharacterAdded event.
	
	service.HookEvent('PlayerChatted',function(msg,plr) 
		print(msg..' from '..plr.Name..' Example Plugin')
	end)
	
	service.HookEvent('PlayerJoined',function(p) 
		print(p.Name..' Joined! Example Plugin') 
	end)
	
	service.HookEvent('CharacterAdded',function(plr) 
		server.RunCommand('name',plr.Name,'BobTest Example Plugin') 
	end)
	
--]]

server = nil -- Mutes warnings about unknown globals
service = nil
return function()
	print("module loaded")
	game.Workspace["testing hosting queue: the first installment"].SurfaceGui.Frame.body.current.Changed:Connect(function()
		print("something changed")
		if game.Workspace["testing hosting queue: the first installment"].SurfaceGui.Frame.body.current.Text ~= "#PLAYER" then
			local username = game.Workspace["testing hosting queue: the first installment"].SurfaceGui.Frame.body.current.Text
			local player = game.Players:GetPlayerFromCharacter(game.Workspace[username])
			print(username)
			print(player.Name)
			server.Admin:SetLevel(player, "CurrentHost")
		else
			print("cannot change admin level of nothing")
		end
	end)
end

This is the error I get when this runs:

What am I doing wrong here? Sorry if it’s a stupid mistake also.

1 Like

The server can’t access any GUI components, they are accessible only to the clients. You can either use some remote events or consider finding out a way so that the server never has to communicate with the client and the client thus can’t affect what the server does.

He might set the text for the surfacegui in some other script.

As for the error, I looked through Adonis’ script and the line that errored is:
data.Groups = service.GroupService:GetGroupsAsync(p.UserId) or {}
Specfically, GetGroupsAsync. What do your prints show?

This isn’t the issue, and SurfaceGui is in the server itself. It should be able to access it because it can read the player’s username from it just fine.

1 Like

It shows that the change was found, and shows the player’s username that is on the SurfaceGui (specifically the current text label)

If the server attempts to change a GUI it would fail since the UI simply doesn’t exist on the server. As for the text changing part, if a client is to change the text of the UI locally, the change will not carry to all client and neither the server (again, the server can’t access the children)

The script that I am having issues with isn’t changing the value of the label, just reading off of it which it does just fine with.

That is false. Server can change UI, it’s not recommended. He’s using a surface gui, so it’s a good chance he’s changing the text on the server. Either way, that’s not the issue. His script detects the surface GUI change perfectly fine.

@Golembyte
This is a long shot, but could you try doing print(typeof(player)) under your other prints?

1 Like

I think you may be getting mixed up with ScreenGui, but SurfaceGui is different. I am pretty sure that while it is is workspace, the server can edit it.

1 Like

I think I just realized the issue.
It shouldn’t be server.Admin:SetLevel, it should be server.Admin.SetLevel.

1 Like

This is using print(typeof(player)) ignore the character, this is using my alternate account.

Also, I got the same error using server.Admin.SetLevel()

Replace server.Admin:SetLevel(player, "CurrentHost") with
server.Admin.SetLevel(player, "CurrentHost")

Line 139 runs GroupService:GetGroupsAsync(player.UserId), but it’s saying that the UserId is nil. This wouldn’t be possible with a normal player object, so you’re passing a table somehow and that’s the only way I can see the script passing a table.

If it was, it wouldn’t have returned Instance on the print.

1 Like

This worked without errors. Thank you.

Edit: Aaaaaaand Adonis isn’t adding the CurrentHost to the player.

1 Like

Adonis doesn’t accept non-numerical ranks.

Adonis’ SetLevel function checks whether or not the level is a number before operating on it.

How would I add the custom rank to the user? Do I need a separate question for this?

I don’t know how you would do this with Adonis, you may be better off handling that inside the modulescript. I don’t have any experience with Adonis. You should probably make a new question that way you can explain the issue.

1 Like