This module script function fires a bindable event with the player parameter.
function TheValleyFunctions.GetInventoryFromServer(Player)
print(Player)
game.ReplicatedStorage.Inventory.MapInventoryBindable:Fire(Player)
return game.ReplicatedStorage.Inventory.MapInventoryBindable.Event:Wait()
end
And this is the function that gets called when that event is fired:
local function GetInventoryFromServer(Player)
warn(Player)
local PlayerInventory = InventoryTables[Player.UserId]
print(PlayerInventory, "This is the inventory when mapping")
RS.Inventory.MapInventoryBindable:Fire(PlayerInventory)
end
RS.Inventory.MapInventoryBindable.Event:Connect(function(Player) GetInventoryFromServer(Player) end)
print(Player) gives me the player name, however warn(Player) in the other script gives me nil. What happened to the Player parameter?
Both are server scripts, but the script calling the module function gets the player info it needs from another local script.
local function Activated(Player,SelectedIngredient)
local PlayerGui = Player.PlayerGui.ScreenGUI
local MolcajeteGui = PlayerGui.Molcajete
local GrindButton = MolcajeteGui.Grind
local Inventory = TheValleyFunctions.GetInventoryFromServer(Player)
warn(Player)
...
Not sure why this information is lost you could try something like this:
function TheValleyFunctions.GetInventoryFromServer(Player)
print(Player)
game.ReplicatedStorage.Inventory.MapInventoryBindable:Fire(Player.Name)
return game.ReplicatedStorage.Inventory.MapInventoryBindable.Event:Wait()
end
local Players = game:GetService("Players")
local function GetInventoryFromServer(PlayerName)
local Player = Players:FindFirstChild(PlayerName)
warn(Player)
local PlayerInventory = InventoryTables[Player.UserId]
print(PlayerInventory, "This is the inventory when mapping")
RS.Inventory.MapInventoryBindable:Fire(PlayerInventory)
end
RS.Inventory.MapInventoryBindable.Event:Connect(GetInventoryFromServer(Player))
Sorry for the late response, but I don’t know if this’ll work since the Player parameter in the function is nil, so it would try and grab a nil player by doing doing that.
The local script returns the player’s name. I checked earlier with print statements and Player.Parent prints Players. When local function GetInventoryFromServer(PlayerName) is called, PlayerName was nil, so the code would essentially do Players:FindFirstChild(nil)
Should I try and get the inventory of the player from the LocalScript instead and pass that as a parameter to Activated() via the remote event? (Activated is triggered by this:
function TheValleyFunctions.GetInventoryFromServer(Player)
print(Player)
return game.ReplicatedStorage.Inventory.MapInventoryRemote:InvokeServer(Player) --Use remote function
end
local function GetInventoryFromServer(Player)
warn(Player)
local PlayerInventory = InventoryTables[Player.UserId]
print(PlayerInventory, "This is the inventory when mapping")
return PlayerInventory
end
RS.Inventory.MapInventoryRemote.OnServerInvoke = function(Player)
return GetInventoryFromServer(Player)
end)