So I have a phone in my game, and in that phone i have a messaging app where players can message each other, I’m done with it, I’m just having trouble figuring out a way to display the message one player sends to another. Right now when a player sends a message it is only adding that message gui to the local player (The player who is sending the message), how can I get it to also add the gui into the receiving players gui (The player receiving the messaging).
You would need to use remote events
When the player sends the message, call :FireServer and the server will receive the message
When the server receives the message, the server calls :FireClient on the recipient, and the recipient displays the text on their gui
How can I get the playergui of the receiving player?
well i would use a remote functionn
client
local remote = --put the path to the remote function here
--whenever you want to get someones gui
local gui = remote:InvokeServer(player) -- the player is the instance of the other player
--give gui for other players
local function Gui()
return --gui instance here
end
remote.OnClientInvoke = Gui
server
local remote = -- path to remote here
-- function to deal with server invoke
local function Func(p,player)
return remote:InvokeClient(player)
end
remote.OnServerInvoke = Func
then from there use the gui the function returns for what you need
Script when the player sends a message:
local RS = game:GetService("ReplicatedStorage")
local RE = RS:WaitForChild("RemoteEvents")
script.Parent.Activated:Connect(function()
local msg = script.Parent.Parent.MessageContent
local Recipent = script.Parent.Parent.Name
local Sender = game.Players.LocalPlayer
print(Sender,Recipent,msg.Text)
RE.SendMsg:FireServer(msg.Text, Recipent, Sender.Name)
wait()
script.Parent.Parent.MessageContent.Text = ""
end)
Server Side Script:
RemoteEvents.SendMsg.OnServerEvent:Connect(function(player, msg, rec, send)
local filter = game:GetService("Chat"):FilterStringForBroadcast(msg,player)
local RecPlayer = game.Players:WaitForChild(rec)
print(RecPlayer,rec)
print(filter)
end)
Ok so right now I’m not yet adding the gui to the player, I’ve been trying to get the receiving players name, but its having issues finding a player with the same name as “rec” when I print rec, it comes up with the name player who is meant to be receiving it, but when i print RecPlayer which should be the actual player in the server it just comes up with nil.
I’m sorry im really bad at explaining, hope you guys can still understand though
Fixed the issue, I was trying to clone the TextGui into a frame that didn’t exist.