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?
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