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

Problem with RemoteEvent firing, help?

LocalScript

main:WaitForChild("giveBtn").MouseButton1Down:connect(function()
	re:FireServer("giveTicket",main:WaitForChild("main"))
end)

Server Script

re.OnServerEvent:connect(function(plr,event,main)
	if event == "giveTicket" then
		print(main.Name)
	end
end)

"main" is a Frame that I want to pass to a Server Script so the script can grab text from it and it keeps outputting this

ServerScriptService.TicketSystemHandler_ss:15: attempt to index local 'main' (a nil value) Script 'ServerScriptService.TicketSystemHandler_ss', Line 15 Stack End

I know the variables definitely exist since I can print their names in the LocalScript, can anyone help? If you need the full script just ask

1 answer

✓ Accepted answer

The Issue

Anything created on the client remains only on the client. When using StarterGui to provide the client with GUI, the parented Instances are cloned locally to the player's PlayerGui. Your current script passes an Instance that exists only on the client into re:FireServer(). When the server receives the signal, the argument will be nil.

The Solution

Simply pass the value of main.Name itself, or any other property of the Instance that you need.

Nitpicks

  • RBXScriptSignal:connect() is deprecated in favour of RBXScriptSignal:Connect().

The Code

###LocalScript

main:WaitForChild("giveBtn").MouseButton1Down:Connect(function()
	re:FireServer("giveTicket", main:WaitForChild("main").Name)
end)

###Script

re.OnServerEvent:Connect(function(plr, event, main_name)
	if event == "giveTicket" then
		print(main_name)
	end
end)

I hope this helped!

1 comment

0

Thanks man!

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