Hello! I have a script that allows players to use the command “:message (user) (message)” to send messages, which then clones a GUI to display the user’s messages. However, when another player tries to reply using the focus lost function script, the reply message is not sent back to the original sender.
Client Sided Script
local remote = game.ReplicatedStorage.UIRemotes.message
local playerToggle = false
local function cloneMessage(clone, toggle)
local from = clone:FindFirstChild("fromPlayer")
local sendTo = clone:FindFirstChild("sendTo")
local playerSent = game.Players:FindFirstChild(from.Value)
local playerReceieved = game.Players:FindFirstChild(sendTo.Value)
if toggle then
clone.UserMessage.Text = script.Parent.Text
clone.From.Text = "Message from " .. playerReceieved.Name
clone.Visible = true
clone.Parent = playerSent.PlayerGui.ScreenGui.ScrollingFrame
script.Parent.Parent:Destroy()
else
clone.UserMessage.Text = script.Parent.Text
clone.From.Text = "Message from " .. playerSent.Name
clone.Visible = true
clone.Parent = playerReceieved.PlayerGui.ScreenGui.ScrollingFrame
script.Parent.Parent:Destroy()
end
end
script.Parent.FocusLost:Connect(function(enterPressed)
if enterPressed then
local clone = script.Parent.Parent:Clone()
if playerToggle then
cloneMessage(clone, true)
playerToggle = false
else
cloneMessage(clone, false)
playerToggle = true
end
end
end)
Server Sided Script
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.From.Text = "Message from "..plr.Name
clone.Name = "Message"
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)