-
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.
-
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.
-
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)