Adonis Event Plugin

Hey, so I’m trying to make an event with Adonis to check when something is changed in the workspace and change the players admin level. I don’t know how to use MakePluginEvent. It says it there in the ExamplePlugin that you can use it but using find in all scripts doesn’t show anything about it in the MainModule.

Any clue here?

1 Like

I don’t know if this is still a valid way of doing it but you used to be able to access the events portion of the adonis services. The makepluginevent is something you can use to make a plugin (as the name suggests) instead of using the plugin scripts provided. If you are wanting to do what you are asking then using a standard event and a normal plugin is what you should be trying to do.

-- One script
service.Events.EventName:connect(function()
-- stuff
end)

-- Another script
-- If this script isn't part of an adonis plugin you can use the _G.Adonis API to get the adonis services.
-- More info on the _G.Adonis API can be found in the API modulescript located in the loader.

service.Events.EventName:Fire()

Edit: After checking, this is still in-fact a valid way of doing it. service.Events.EventName will create a new event, the events name will be whatever you decide to index service.Events with. In this case it would be “EventName”.

hey there, sorry for the late reply.

for the service i have to require the main module correct? sorry im new to creating functions with adonis.

edit: this is what i have right now, i keep getting attempt to index nil with Service with the code below:

script in another model (not adonis)

local adonis = _G.Adonis
adonis.Service.Events.CurrentHost:Fire(...)

script in loader as server plugin

return function()
	service.Events.CurrentHost:Connect(function(source, newhost)
		if source and newhost then
			print("hello")
		end
	end)
end

I believe you have to use the Access function within the adonis global table. Your access key is something you add in your settings module . You will also want to enable Service in Allowed_API_Calls.

local Service = _G.Adonis.Access(AccessKeyInSettingsModule, "Service") -- A list of other things you can access are found inside the adonis settings module.

Service.Events.EventName:Fire(...)

I Haven’t used adonis in a while so this could have been updated but upon quick glance at the settings module it seems plausible.

That is giving me attempt to index nil with 'Access'

Do you have API access enabled in the settings module of the adonis loader? According to the API this is what you should be doing:

--_G.Adonis.Access(accessKey, serverSubTable)
--	- Returns a read-only version of a server subtable; allowing you to use all of it's functions
--	- Settings can be changed in the Settings module for what to allow access to and to change if scripts can read/write

settings.G_Access should be set to true and Service should be set to true aswell inside the settings.Allowed_API_Calls. This is the section you should be looking at:

image

This is what I have right now. Obviously this isnt the key I am using.

If you have it set up properly it shouldn’t be returning nil, that being said Adonis hasn’t been updated in a while and the _G API might not even be working at this point. What is your goal exactly with what you are trying to create? You could probably use entirely plugins to accomplish what you are trying to make instead of having to access _G.

When a text value is updated, change the rank of the player so they can access some commands they wouldn’t normally be able to use.

So i just tested it and it worked fine.

Adonis Server plugin

server = nil 
service = nil

return function()
	service.Events.Test.Event:Connect(function(message)
		print(message)	
	end)
end

Seperate Server script accessing the Adonis API

local Players = game:GetService("Players")

repeat wait() until _G.Adonis


local Service = _G.Adonis.Access("MyKey", "Service")

local function HandlePlayer(Player)
	Player.Chatted:Connect(function(Message)
		Service.Events.Test:Fire(Message)	
	end)
end

for _, Player in pairs(Players:GetPlayers()) do
	HandlePlayer(Player)
end

Players.PlayerAdded:Connect(HandlePlayer)

Weird, when I test it in an actual game, it works.

Adonis is really only designed to be used on an actual server so that makes sense. I remember that being the case, probably should have mentioned it.

Didn’t know that, thanks for all your help.

Just mark whatever post helped or reply with your solution, if someone else has the same problem they can have somewhat of an idea how to handle it.

1 Like