I have this control that handles when an item is given and removed from a player, to handle specific interactions. Basically, each item in game has this sort of module, and it’ll be a way to have each item have their own specific actions occur, without needing a massive script to handle every single item and its unique acitons.
local Control = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Trove = require(ReplicatedStorage.Packages.Trove)
function Control:Init()
self.Trove = Trove.new()
if RunService:IsServer() then
self.Trove:Connect(script.Parent.RemoteEvent.OnServerEvent, function(player)
print("FIRED", player)
end)
else -- Client
self.Trove:Connect(UserInputService.InputBegan, function(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if
input.UserInputType ~= Enum.UserInputType.MouseButton1
and input.UserInputType ~= Enum.UserInputType.Touch
then
return
end
script.Parent.RemoteEvent:FireServer()
end)
end
end
function Control:Destroy()
self.Trove:Destroy()
print("Disconnect handeling")
end
return Control
My question is, is this a good structure?

I require it on both client and server when an item with the Control script exists, and run destroy when that item is removed from the character, do any disconnects. Also curious if I need to worry about a player leaving with item in hand? if that’d cause memory leaks? as I’m sure how could check for that kinda stuff? as I’m storing the connection with the item as the key?
local Control = Clone:FindFirstChild("Control")
if Control then
self.ItemControls[Clone] = require(Control)
self.ItemControls[Clone]:Init()
end
Unsure if I just go with regular script/local script combination for server-client communication? As it’d be easier to handle, no need to require anything, pretty sure connections automatically disconnect when script is destroyed, so there’d be no issues + would mean all clients would automatically have the local side of the code going, wouldnt need to do some crazy requiring to get all the clients to require the tool. Problem tho is the object gets parented to the character, thus LocalScript wouldn’t run
so unsure what to do there