Remote event doesn't fire the client properly

  1. I want to make an inventory system. At first I made the GUI and then started scripting the inventory and the items. The item script works fine but the inventory script doesn’t.

  2. When the item is clicked, Its supposed to fire a remote event that contains the name of the item to the player that clicked on it. After that, a local script that is inside of the inventory GUI is supposed to receive the name of the item from the remote event and put the item inside of the inventory. After the player clicks on the item it fires the remote event to the client but the local script doesn’t seem to detect the remote event when its fired.

  3. I first tried other ways of getting the player who clicked because I thought maybe it couldn’t find the client properly but that still didn’t work. I read different threads on the Dev Forum about this issue but none of them were helpful.

Item script :

local Item = script.Parent
local Players = game:GetService("Players")
local NameString = tostring(Item.NameVal.Value) -- the name value of the item
local ClickD = Item.ClickDetector

local ItemPickupEvent = game.ReplicatedStorage.ItemPickedUp -- the remote event
ClickD.MouseClick:Connect(function(clicker) --item was clicked
	local CurrentPlayerIndex = Players:GetPlayers() --get table of all players
	local plrIndex = table.find(CurrentPlayerIndex,clicker)
	local plr = CurrentPlayerIndex[plrIndex] --get the player from players table
	ItemPickupEvent:FireClient(plr,NameString)
	print(plr,NameString) -- prints the player and the item's name
end)

Local script:

--inventory
local InventoryGUI = script.Parent.BackpackBG

local ItemPickupEvent = game.ReplicatedStorage.ItemPickedUp -- the remote event
ItemPickupEvent.OnClientEvent:Connect(function(NameString)
	print(NameString) --nothing happens after its fired
end)

the “clicker” will be the player instance, not the “item” that was clicked.
so you don’t need to get all the players and find the player that clicked the ClickDetector.

can’t you just do this

ClickD.MouseClick:Connect(function(plr) --item was clicked
	ItemPickupEvent:FireClient(plr,NameString)
	print(plr.Name, NameString) -- prints the player and the item's name
end)

It does the same thing it did before.
image

where is the localscript located?

Sorry for responding late, the local script is located in StartedGui under the inventory ScreenGui.