Hello Devfourm, I am trying to get a Textbox’s text from the client and send it to the server through a RemoteEvent. When I get the text from the textbox and send it through the RemoteEvent that was to set a part in the workspace transparency to the textbox’s text, doing that I am using the tonnumber() function. When the Textbox’s text is sent to the function it outputs
“value of type nil cannot be converted to a number”
Here is the server script receiving the event:
local Event = script.Parent.Change
local Part = game.Workspace:WaitForChild("Color_Part")
Event.OnServerEvent:Connect(function()
Part.Transparency = tonumber(Event)
end)
local Button = script.Parent
local TextBox = script.Parent.Parent.TextBox
local Event = script.Parent.Change
local value = TextBox.Text
Button.MouseButton1Click:Connect(function()
Event:FireServer(value)
end)
Server Script:
local Event = script.Parent.Change
local Part = game.Workspace:WaitForChild("Color_Part")
Event.OnServerEvent:Connect(function(value)
print(value)
Part.Transparency = tonumber(value)
end)
The problem here is the „Event“ in the code. „Event“ is an already set variable which contains an instance located at script.Parent.Change. This instance itself is not compatible with tonumber().
As others already have mentioned, you need to pass the text in the LocalScript you fire the event. First variable is the player instance that the LocalScript fired from and second variable is the one you passed.
Now, you said when printing out that second argument, it returns blank. Could you print out the value before you pass it like this:
local Button = script.Parent
local TextBox = script.Parent.Parent.TextBox
local Event = script.Parent.Change
Button.MouseButton1Click:Connect(function()
print(TextBox.Text)
Event:FireServer(TextBox.Text)
end)
If this returns blank then your textbox seems to contain no text.