How to access plugin keyword from a module script

I’m new to making plugins and am trying to save some data using plugin:GetSetting() and plugin:SetSetting() in a module script, however it says that the keyword plugin is nil. When I tried doing the same thing from the main script it worked as expected, however if I require a module using that main script the module will not have the plugin keyword.

I tried changing the parent of the module and putting plugin into the module but nothing worked.

Here is how it’s setup in the explorer if that matters:
image

A similar thing happened with my plugin, you are going to have to fire a bindable function from the module script to the main script to get the data and use a bindable event to save it. Like so:

--This would go in the Script
script.Parent.GetData.OnInvoke = function()
		local Data = plugin:GetSetting("UI Plugin")
		if not Data then
			return {}
		end
		Data = game:GetService("HttpService"):JSONDecode(Data)
		return Data
end

local function SetRaw(Data)
	Data = game:GetService("HttpService"):JSONEncode(Data)
	plugin:SetSetting("UI Plugin",Data)
end
script.Parent.SetData.Event:Connect(SetRaw)
1 Like

Works perfectly thank you