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

Why cant I pass arguments in Remote Functions?

Im trying to pass string values from a GUI text box to a StringValue's value. But I cant seem to pass arguments, for some reason both hit and arg1 print out as the player, other arguments turn out to be nil, idk why.

Server script

local event = Instance.new("RemoteEvent") 
event.Parent = game.Workspace
event.Name = "MyServerEvent"
event.OnServerEvent:connect(function(Player,hit,arg1,arg2,arg3)
if not game.workspace.Events:FindFirstChild('meep') then

		*EVENTS IS A FOLDER IN WORKSPACE*

	print(player)
	print(hit)
	print(arg1)
	print(arg2)
	print(arg3)

--it prints
--player1
--player1
--nil
--nil
--nil
--only error I get from the server is this
-- * Workspace.Remoteevent:16: attempt to index local 'track' (a nil value)*
-- *Stack Begin*
-- * Script 'Workspace.Remoteevent', Line 16*
-- *Stack End*

	local fold = Instance.new("Folder",game.Workspace.Events)
	fold.Name = "meep"
	local arg1main= Instance.new("StringValue",game.Workspace.Events[""..fold.Name])
	arg1main.Value = track.Text
	
	
	local arg2main= Instance.new("StringValue",game.Workspace.Events[""..fold.Name])
	arg2main.Value = class.Text

	local arg3main= Instance.new("StringValue",game.Workspace.Events[""..fold.Name])
	arg3main.Value = laps.Text

	
end
local namz = Instance.new("ObjectValue",game.workspace.Events.Race)
namz.Name = hit.UserId

end)

Local Script

local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = game.workspace.event
clickDetector.MouseClick:connect(function(Player,hit,arg1,arg2,arg3)

	local arg1= game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.arg1.TextBox
	local arg2=  game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.arg2.TextBox
	local arg3=  game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.arg3.TextBox
	game.Workspace.MyServerEvent:FireServer(Player,hit,arg1,arg2,arg3)
	
end)

1 answer

✓ Accepted answer

The first argument on the receiving side of a RemoteEvent is the player the request came from. After that comes the parameters supplied to the event.

event.OnServerEvent:connect(function(who, hit,arg1,arg2,arg3)
	........

will make your code work.


I don't know why you're doing "" .., that's pointless. fold.Name is a string, putting nothing on front doesn't change it.

You should use workspace instead of game.Workspace, it's shorter.

You shouldn't be using workspace.Events[fold.Name] when you mean just to use fold.

local a = Instance.new("StringValue", fold)
a.Value = foo

You can't send TextBoxes over, because those objects only exist on the client. The server doesn't pay attention to GUI objects, because they should only be updated by LocalScripts (anything else has too high of latency to be what you want)

3 comments

0

I have to disagree on one point. While it is longer, using game.Workspace is good practice.

0

Thanks for the insite, but its not my original code and have yet to clean it up. I just wanted functionality and the "".. comes in at a later stage. But ill test it out when I get a chance, thanks.

0

Ok, it still wont work, when I print all 3 arguments it prints it nil.

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