Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Problem with RemoteEvent firing, help?

Asked by 5 years ago

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

Log in to vote
0
Answered by
BenSBk 781 Moderation Voter
5 years ago

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!

0
Thanks man! ShiforRBLX 5 — 5y
Ad

Answer this question