Value not being transferred through remote events

I’m trying to transfer a value which is in server storage to a local script so I decided to use remote events. I made a event that should get the MaxAmount and then send it to the client but it doesn’t change.

Normal script:

local function(player, itemname, ItemAmount)
		local item = game.ServerStorage.Inventory:FindFirstChild(player.Name):WaitForChild("Data"):WaitForChild("Items")[itemname]
		local itemCore = item
		local MaxAmmount = item:WaitForChild("Amount").Value
		C1:FireClient(player, itemCore, MaxAmmount)

Local script:

local SelectedItem
local MaxAmountVal = 2
C1.OnClientEvent:Connect(function(itemCore, MaxAmmount)
	MaxAmountVal = MaxAmmount
	SelectedItem = itemCore
end)

c1 is the remote event. I want the MaxAmountVal to change depending on the value MaxAmount on the server side.

Because the item is in ServerStorage which is impossible for the client to reach into. I suggest you put the tool somewhere else.

im getting item from a script in serverscriptservice and im getting the value from the amount from item. then in the local script i want to get that value

itemCore is a reference to an instance in ServerStorage. Since ServerStorage is not replicated to the client, the client will resolve the reference to nil. This means SelectedItem will always be nil.

However, you appear to be replicating MaxAmmount correctly. Sending Value instead of a reference to the instance. Perhaps you meant to do this for itemCore?

no, itemcore does nothing atm. But the MaxAmmount is special and doesn’t want to work

Could you try putting print here? It might sounds a bit unnecessary but I just wanna know if it’s nil or if it’d print.

local SelectedItem
local MaxAmountVal = 2
C1.OnClientEvent:Connect(function(itemCore, MaxAmmount)
    print(itemCore, MaxAmmount) -- Prints
	MaxAmountVal = MaxAmmount
	SelectedItem = itemCore
end)
1 Like

I was able to get it working but thanks for your help.

2 Likes