I'm trying to insert a message into someone else's PlayerGui through a localscript. Is that possible? If so, how?
COMMUNITY QUESTION
How would I access someone else's PlayerGui in a localscript?
3 answers
like a message as in
Instance.new('Message')
?
Coming from a noob, I think
local PlayerAdded = game.Players.PlayerAdded:connect(function(plr)
local Message = Instance.new("Message",game.Players.LocalPlayer.PlayerGui)
Message.Text = "You're text"
end)
So when the Instance.New message goes into the LocalPlayers' PlayerGUI
If you're using FilteringEnabled (and possibly even if you're not, I'm not sure), you will need to have RemoteEvents. Assuming your RemoteEvent is in the workspace and is named RelayMessage, something like this:
--Server script
workspace.RelayMessage.OnServerEvent:connect(function(sender, target, msg)
workspace.RelayMessage:FireClient(target, msg)
end)
--Local script
workspace.RelayMessage.OnClientEvent:connect(function(msg)
--deal with msg here
end)
--Send a message to someone else like this:
workspace.RelayMessage:FireServer(somePlayer, someMsg)
Note: a proper server-side function might make sure of the following things to prevent exploiters/hackers from doing too much damage:
- That the message is appropriate and not ridiculously long (ex it could be a number referring to a pre-made message if you wanted to be 100% safe)
- That the sender isn't spamming people or the server using a bot (if they are, you should kick them)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
yeah but parent it to their PlayerGui
when I try to parent it to their PlayerGui, it returns an error "PlayerGui is not a valid member of Player"
Can you show me what your script looks like?
Oh my goodness.