Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why do I get a bad argument for this RemoteFunction?

local train = script.Parent.V.Value local textFunc = train:WaitForChild("TextFunction")

script.Parent.Frame.TextBox.Changed:connect(function(prop) if prop == "Text" then textFunc:InvokeServer(script.Parent.Frame.TextBox.Text) --Line 7 of local script end end)

 
~~~~~SCRIPT~~~~~~~~~

local ReplicatedStorage = game:GetService("ReplicatedStorage") local textFunc = Instance.new("RemoteFunction") textFunc.Parent = script.Parent textFunc.Name = "TextFunction"

local function onTextRequested(text) for i, v in pairs(script.Parent:GetChildren()) do if v.Name == "RearCar" or v.Name == "CenterCar" then v.TxtVal.Value = text -- this is line 9 in the script end end end

textFunc.OnServerInvoke = onTextRequested




When I change the text of the textbox, causing InvokeServer, the output returns:
Workspace.Train.Text Event Script:9: bad argument #3 to 'Value' (string expected, got Object)
It says the source of the error Is line 7 of the local script.

Why does it say it got an Object if I provided the argument (script.Parent.Frame.TextBox.Text) which is a string??

3 comments

0

Try printing out text to see what comes up.

0

Wait I see the issue haha

0

the first argument is player, the second is text

1 answer

So the issue here is the first value of the remoteFunction is player however you labeled it as text so its trying to insert the player as text. To fix this do this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local textFunc = Instance.new("RemoteFunction")
textFunc.Parent = script.Parent
textFunc.Name = "TextFunction"

local function onTextRequested(player, text)
	for i, v in pairs(script.Parent:GetChildren()) do
		if v.Name == "RearCar" or v.Name == "CenterCar" then
       	 		v.TxtVal.Value = text -- this is line 9 in the script
   	 	end
	end
end

textFunc.OnServerInvoke = onTextRequested

This discussion is preserved as it was. New answers, comments, and votes are closed.