Attempt to index nil with 'Value'

Hello everybody! I ran into such a problem that when I launch a remote event on the client for the server and transmit information about the Number Value, namely its currency then when the server receives this information, it writes that it is zero.

Error:
(ServerScriptService.Shop:32: attempt to index nil with 'Value ')

LocalScript (located in the StarterGui):

BuyEvent:FireServer(ItemCost,ItemLvl,NameItem)
—(ItemCost, ItemLvl, NameItem this is a NumberValue)

Script (located in the ServerScriptService):

BuyEvent.OnServerEvent:Connect(function(plr,ItemCost,ItemLvl,NameItem)
print(plr.Name)
print(ItemCost.Value)
print(ItemLvl.Value)
end)

And if you print the values of these Number Values in Local Script, then it will print them without a problem, and in script it already gives an error.

If the instance you’re trying to send to the server is inside a PlayerGui, the server will not be able to read it. Instead, try this:

Client:
BuyEvent:FireServer(ItemCost.Value,ItemLvl.Value,NameItem.Value)

Script:

BuyEvent.OnServerEvent:Connect(function(plr,ItemCost,ItemLvl,NameItem)
print(plr.Name)
print(ItemCost)
print(ItemLvl)
end)

P.S: Never set the item price on the client as it is very easy for an exploiter to change it to 0

1 Like

The server has access to the PlayerGui, what @Hac_kYouTube does is to create or access a NumberValue created in LocalScript.

The server has access to only GUIs that have been given from the server, not from the StarterGui.

1 Like

No?, both UI’s are exactly the same and the view is from the server


image
As you can see, the server knows that there are.


Objects cloned or using Instance.new in local context will never be visible to the server.

1 Like

Yes, after making some experiments myself, it turns out you were right about the fact that only instances created by the client are invisible to the server which is probably OP’s case since he’s making a shop.

Thank you so much, now everything works as it should!

1 Like

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