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

Problem with RemoteEvents, any help?

Asked by
peely09 15
9 years ago

I've made a custom chat Gui and after making modifications, it seems to have broken. I have a LocalScript in the PlayerGui that's listening for an OnClientEvent that is being called from a server script, with the argument passed through being a TextLabel with the players chatted message. The label is being created fine on the server but my LocalScript is saying it doesn't exist; it's nil.

Appropriate code inside the server script

local event = Instance.new('RemoteEvent', script) ; event.Name = 'on_chatted'
event:FireAllClients(msg_label)

msg_label is a local variable holding the created TextLabel

Appropriate code inside the local script

event.onClientEvent:connect(function(label)
    shift_labels(label)
end)

The function is regardless for this matter as 'label' apparently doesn't exist.

Am I being stupid? Missing something obvious?

Any help appreciated.

EDIT:

I changed event:FireAllClients(msg_label) by replacing msg_label with an integer, 1.

local event = Instance.new('RemoteEvent', script) ; event.Name = 'on_chatted'
event:FireAllClients(msg_label)
event.onClientEvent:connect(function(x)
    print(x)
end)

The client was able to print the value I sent through, 1. So the problem seems to be with passing a reference to an object. Is this just not doable? If so, is there a workaround?

0
Full Script please? and, WaitForChild, don't forget that. NathanAdhitya 124 — 9y
0
The full scripts aren't necessary, I just wanted to know if there was anything preventing the passing of objects from server to client like I'm trying to do here. peely09 15 — 9y

1 answer

Log in to vote
0
Answered by
peely09 15
9 years ago

I think I understand. My problem seems to have been solved by first parenting the TextLabel to the server script. That way, you're sending an actual object through to the client rather than just a reference that only exists inside the server script

msg_label.Parent = script
event:FireAllClients(msg_label)

I was then able to parent the TextLabel from the server script to the GUI on the client

Ad

Answer this question