Attempting to send Number Value from client to server side, Given "value of type Instance cannot be converted to a number" error

Hi Developers,
I am trying to send a NumberValue from Client to Server-side , However I am given the “value of type Instance cannot be converted to a number” error, is there a way to fix this?
Thanks.

Code from client side:

local Trainvalues = script.Parent.ObjectValue.Value

Trainvalues.Values.Speed.Changed:Connect(function()
	speed:FireServer(Trainvalues.Values.Speed.Value) 
end)

Code from server side:

local connection = script.Parent.Parent.Parent.Value.Value

script.Parent.OnServerEvent:Connect(function(Player, info)
	connection.Values.Speed.Value = info
end)

A bit more context on all the indexes might be needed here, are the Values a child of the ObjectValue or are they a child of the ObjectValue’s stored object?

1 Like

I believe the values are a child of the objectvalue.

So Connection is an object value which is a model which contains the Values.Speed.Value.

1 Like

Based on this:
local Trainvalues = script.Parent.ObjectValue.Value - this redirects to the object itself that is stored in the value, meaning that if the values arent a child of that specific object that the ObjectValue is storing, then you are indexing to nothing

1 Like

As an example:

local Model = ObjectValue.Value --The value is the model, stored inside the ObjectValue
local NumberValue = Instance.new("NumberValue",ObjectValue) --Creates a number value and parents it to the ObjectValue
Model.NumberValue.Value = 5 --Doesnt work because it's a child of the ObjectValue, not of the Model

Am i understanding this right?

1 Like

I’ll show how the thing is organised.


The connection is the “V set”

Hopefully this helps

Is the Values even a child of the connection? Looks like Values and Controls are both children of the same parent

1 Like

Looks like Values are a child of GUI2, I might be blind tho

1 Like

Don’t name your _Value instances just Value cause they actually have a property called Value which corresponds to the actual value / reference (if its ObjectValue)

so either rename your NumberValue to something else or do Value.Value instead

Did he not do that though? He got ObjectValue.Value and Speed.Value

I would say instead of

local connection = script.Parent.Parent.Parent.Value.Value

script.Parent.OnServerEvent:Connect(function(Player, info)
	connection.Values.Speed.Value = info
end)

You would need

local connection = script.Parent.Parent.Parent.Value.Value

script.Parent.OnServerEvent:Connect(function(Player, info)
	connection.GUI2.Values.Speed.Value = info
end)

Edit: Same for the client version in case that is indexed wrongly too

Gui2 is the child of v set
Values is also the child of v set
The connection is the v set

1 Like

I would recommend using prints to figure out the problem, printing the info, the values and so on

It says the value cannot be converted to a number, so I would print the Speed value for a start

You are trying to send the value of an ObjectValue instance to the server, and trying to convert the value stored by that ObjectValue instance into a number, which is impossible.

image
idk why he sent selecting this
and also the
local connection = script.Parent.Parent.Parent.Value.Value
is confusing as hell

Just do local num = toNum(Whatever.Value)

then send that through the remote events.

1 Like