Information is always nil when using FireServer()

I want to transfer over a table of info on items that I have to be read by the server so I can update the players stats from there.

The information that I am sending over is printing out perfectly fine on my local script but when I try and print it out on my server script its returning nil.

Here is my local script:

	for i,v in pairs(items:GetChildren()) do
		local labels = v:FindFirstChild("Labels")
		local equip = labels:FindFirstChild("Equip")
		local properties = v:FindFirstChild("Properties")
		local buffs = properties:WaitForChild("Buffs")

		v.MouseButton1Click:Connect(function()
			equip.Visible = true
			itemTitle.Visible = true

			selected = v

			itemTitle.Title.Text = string.upper(v.Name)
			itemExtraHealthText.Text = "  Extra Health: " .. buffs:FindFirstChild("Health").Value
		end)

		equip.MouseButton1Click:Connect(function()
			if equip.Text == "EQUIP" then
				equip.Text = "UNEQUIP"

				print(buffs) 
				remoteEvent_ItemStats:FireServer(buffs, 1)
				equipped[properties.Type.Value] = equip.Parent.Parent
				
				equip.Parent.Parent.BorderSizePixel = 2
			else

“print(buffs)” returns the folder buffs as intended

Here is my server script:

remoteEvent_ItemStats.OnServerEvent:Connect(function(player, info, action)
	print(player, info, action)
	local playerStats = player:WaitForChild("PlayerStats")
	local itemBuffs = playerStats:WaitForChild("ItemBuffs")
	local extraHealth = itemBuffs:WaitForChild("ExtraHealth")
	local damageMult = itemBuffs:WaitForChild("DamageMult")
	
	local character = player.Character or player.CharacterAdded:Wait()
	local humanoid = character:WaitForChild("Humanoid")
	
	remoteEvent_ItemStats:FireClient(player, itemBuffs)
end)

“print(player, info, action)” returns the player, nil, 1

I’m genuinely so lost as to why it would return nil if anyone has some insight please let me know!

How is items created and is it only visible to the client? If so, then that instance and its children (e.g., buffs) will never pass the client → server boundary. You can read more about why at Remote Events and Callbacks | Documentation - Roblox Creator Hub.

Basically, if the instance you’re trying to pass in the remote event is not a replicated instance, it will end up as nil on the other side.

1 Like

Hello, I looked at your code and I think I have fixed your problem.
client:

for i,v in pairs(items:GetChildren()) do
    local labels = v:FindFirstChild("Labels")
    local equip = labels:FindFirstChild("Equip")
    local properties = v:FindFirstChild("Properties")
    local buffs = properties:WaitForChild("Buffs")

    v.MouseButton1Click:Connect(function()
        equip.Visible = true
        itemTitle.Visible = true

        selected = v

        itemTitle.Title.Text = string.upper(v.Name)
        itemExtraHealthText.Text = "  Extra Health: " .. buffs:FindFirstChild("Health").Value
    end)

    equip.MouseButton1Click:Connect(function()
        if equip.Text == "EQUIP" then
            equip.Text = "UNEQUIP"

            remoteEvent_ItemStats:FireServer(buffs, 1)
            equipped[properties.Type.Value] = equip.Parent.Parent

            equip.Parent.Parent.BorderSizePixel = 2
        else
            -- Handle the unequip logic here if it is needed
        end
    end)
end

Server Side:

remoteEvent_ItemStats.OnServerEvent:Connect(function(player, info, action)
    print("Received server event:")
    print("Player:", player)
    print("Info:", info)
    print("Action:", action)

    local playerStats = player:WaitForChild("PlayerStats")
    local itemBuffs = playerStats:WaitForChild("ItemBuffs")

    local extraHealth = itemBuffs:WaitForChild("ExtraHealth")
    local currentHealth = playerStats.Health
    playerStats.Health = currentHealth + extraHealth.Value

    remoteEvent_ItemStats:FireClient(player, itemBuffs)
end)

I believe this will fix your problem.

1 Like

So I am creating lua items in the client but I am ensure how I could create it in the server as items holds imageLabels which contains information on buffs and whatnot.

-- Runs whenever a NEW item is added
inventoryFolder.ChildAdded:Connect(function(child)
	local rows = 0
	local column = 0
	local numberOfItems = #inventoryFolder:GetChildren()
	
	for i,v in pairs(inventoryFolder:GetChildren()) do
		column = i % 5

		-- Sets what row number the item will be on
		if column == 0 then
			rows = i / 5
		else
			local fixedNumber = i - column
			rows = fixedNumber / 5
		end
		
		for i,asset in pairs(itemAssets:GetChildren()) do
			if v.Name == asset.Name then
				local newItem = asset:Clone()
				newItem.Parent = items
				newItem.Position = newItem.Position + UDim2.new(0.105 * (column - 1), 0, 0.17 * (rows), 0) -- The -1 is so it stars properly
				newItem.Visible = true
				
				local labels = newItem:WaitForChild("Labels")
				local quantity = labels:WaitForChild("Quantity")
				quantity.Text = inventoryFolder:FindFirstChild(newItem.Name).Value
			end
		end
		
	end

Should I create a second folder which will contain the same info but is able to pass through to the server? Like a lua Items2.0 for example and it contains intValues that represent items’ imageLabels which can act as a bridge to the server for information.
If possible, I’d rather not do that as it complicates things a lot but if that’s my only solution then I’ll give it a shot.

What exactly is different to my old code that I had previously? I tried adding in the changes and it didn’t work.

I just modified your code a bit. I thought it would work. I’m sorry

1 Like

Haha no worries, I appreciate all the help! Thanks for pitching in.

1 Like

It’s hard to know what the best solution would be without fully knowing how your game is set up and the architecture.

One suggestion would be to put whatever info the server needs from the buffs folder into an ordinary table and pass that table to the remote event. Tables don’t have the same issue that instances do with remote events (although there can still be issues depending on the structure of the table).

1 Like

OKAY SO IT WORKED! Pretty much, I kinda already had a folder containing the “physical” information my server needs, but I kinda lost track of that since my code is all over the place.
My issue was 100% that I was creating the folder through the client which can’t be accessed by the server. Thank you so much.

1 Like

No problem. Glad you got it working :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.