Hello, I have a script that allows the player to message other players by saying “:Message (user) (message)”, however, whenever the recipient replies, it does not send it back to the sender. I spent long but I couldn’t find any answer
Server-sided script
local remote = game.ReplicatedStorage.UIRemotes.message
local group = 32753307
local rank = 1
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(Message)
if string.lower(string.sub(Message, 1, 5)) == ":open" then
local gateNumber, flightNo = string.match(Message, ":open (%S+)%s+(%S+)")
if gateNumber and flightNo then
for _, player in pairs(game.Players:GetChildren()) do
local ScreenUI = player.PlayerGui:WaitForChild("ScreenGui")
local frame = ScreenUI.ScrollingFrame.InteractableInformation
local clone = frame:Clone()
local flightPart = Instance.new("StringValue", clone)
flightPart.Name = "PartName"
flightPart.Value = gateNumber
clone.Parent = ScreenUI.ScrollingFrame
clone.Visible = true
clone.TP.Text = "Teleport to Gate " .. gateNumber
clone.Message.Text = "Flight " .. flightNo .. " is now ready for boarding at gate " .. gateNumber .. ",\nPlease make your way there."
end
end
end
end)
plr.Chatted:Connect(function(Message)
if string.lower(string.sub(Message, 1, 8)) == ":message" then
local user, message = string.match(Message, ":message (%S+)%s+(.+)")
local player1 = game.Players:FindFirstChild(user)
if player1 then
local clone = player1.PlayerGui.ScreenGui.ScrollingFrame.Message:Clone()
clone.Name = "MessageClone"
clone.From.Text = "Message from "..plr.Name
clone.UserMessage.Text = message
clone.Parent = player1.PlayerGui.ScreenGui.ScrollingFrame
clone.Visible = true
local sendTo = Instance.new("StringValue", clone)
sendTo.Name = "sendTo"
sendTo.Value = player1.Name
local fromPlayer = Instance.new("StringValue", clone)
fromPlayer.Name = "fromPlayer"
fromPlayer.Value = plr.Name
end
end
end)
end)
local function cloneMessage(plr, clone, toggle, text)
local from = clone:FindFirstChild("fromPlayer")
local sendTo = clone:FindFirstChild("sendTo")
local playerSent = game.Players:FindFirstChild(from.Value)
local playerReceived = game.Players:FindFirstChild(sendTo.Value)
if playerSent and playerReceived then
clone.Parent = workspace
if toggle then
clone.UserMessage.Text = text
clone.Name = "AnotherMessageClone"
clone.From.Text = "Message from " .. playerReceived.Name
clone.Visible = true
clone.Parent = playerSent.PlayerGui.ScreenGui.ScrollingFrame
else
clone.UserMessage.Text = text
clone.From.Text = "Message from " .. playerSent.Name
clone.Visible = true
clone.Parent = playerReceived.PlayerGui.ScreenGui.ScrollingFrame
end
else
warn("Invalid player names: " .. from.Value .. " or " .. sendTo.Value)
end
end
remote.OnServerEvent:Connect(function(plr, toggle, text)
local clone = plr.PlayerGui.ScreenGui.ScrollingFrame.MessageClone:Clone()
if toggle then
cloneMessage(plr, clone, true, text)
toggle = false
else
cloneMessage(plr, clone, false, text)
toggle = true
end
end)
Client-Sided Script
local remote = game.ReplicatedStorage.UIRemotes.message
local playerToggle = true
script.Parent.FocusLost:Connect(function(enterPressed)
if enterPressed then
script.Parent.Parent.Visible = false
local text = script.Parent.Text
if playerToggle then
remote:FireServer(true, text)
playerToggle = false
else
remote:FireServer(false, text)
playerToggle = true
end
end
end)