How to isolate a specific listener in a RemoteEvent

I have a tool where I can clone items from ReplicatedStorage and put them inside the player’s backpack when a button is clicked. The script for the tool is inside the tool. The cloning works perfectly, but the issue is that when there is more than one briefcase (tool), all of the briefcases in the workspace spawn their own duplicate of the tool because they’re all listening for the same event. Is there a way to get around this and make it so that only one item is cloned regardless of the amount of listeners in the workspace?

GuiButton Example

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Button = script.Parent
local ItemIdentificator = "Scholar"

local function onActivated()
	
	ReplicatedStorage.ItemGiveEvent:FireServer("Scholar", ItemIdentificator)
	print("fired!")
	
end

Button.Activated:Connect(onActivated)

Portion of the script inside the tool

ReplicatedStorage.ItemGiveEvent.OnServerEvent:Connect(function(Player, ItemIdentificator)
	
	print(Player)
	print(ItemIdentificator)
	player = Player
	
		
		if ItemIdentificator == "Ornate" then

			local Light_OrnateLantern = game.ReplicatedStorage:WaitForChild("Ornate Lantern"):Clone()
			Light_OrnateLantern.Parent = player.Backpack

		elseif ItemIdentificator == "Librarian" then
			
			local Light_LibrarianCandle = game.ReplicatedStorage:WaitForChild("Librarian's Candle"):Clone()
			Light_LibrarianCandle.Parent = player.Backpack
			
		elseif ItemIdentificator == "Seeker" then
			
			local Light_SeekerCandle = game.ReplicatedStorage:WaitForChild("Seeker's Candle"):Clone()
			Light_SeekerCandle.Parent = player.Backpack
			
		elseif ItemIdentificator == "Wayfarer" then
			
			local Light_WayfarerCandle = game.ReplicatedStorage:WaitForChild("Wayfarer's Candle"):clone()
			Light_WayfarerCandle.Parent = player.Backpack
			
		elseif ItemIdentificator == "Scholar" then
			
			local Light_ScholarCandelabra = game.ReplicatedStorage:WaitForChild("Scholar's Candelabra"):Clone()
			Light_ScholarCandelabra.Parent = player.Backpack
			
		elseif ItemIdentificator == "Briefcase" then
			
			local Utility_Briefcase = game.ReplicatedStorage:WaitForChild("Briefcase"):Clone()
			Utility_Briefcase.Parent = player.Backpack
			
		end
		
		
	end)

image

One click as a result of multiple briefcases.

Thank you for any help!

I can’t immediately see the issue in the code, but I did notice that you are sending what should be the same value twice

local ItemIdentificator = "Scholar"
...
ReplicatedStorage.ItemGiveEvent:FireServer("Scholar", ItemIdentificator)

How many times does

print("fired!")

activate per click?


What is the output of these? Are they what you want them to be?

print(Player)
print(ItemIdentificator)

The same value twice was an old workaround when I was having an issue with Playernames, but changing it to not send both values doesn’t change the issue.

Fired only activates once per click of the guibutton.

And the output is as expected!
image

The issue is that when there are multiple instances of the briefcase tool, they all spawn the item on the click of the guibutton. So if there are two briefcases then two Scholar’s Candelabras will spawn, four briefcases will then make four Candelabras, ect…

Move item giver script from the tool to the server script service.

This probably works, but doing it is creating a whole plethora of other issues. How do I create a variable for a tool that moves between the backpack and character model in ServerScriptService?

What do you mean? What do you want to share between scripts?

I want to define the tool first. I don’t know how to define the tool when it constantly moves between the player’s backpack and character and I can’t use Script.Parent.