Messages not toggling

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)

Why is there a remote but you’re not using it? You could use a remote function to communicate back and forth from the clients to the server.

I did try to use it and it still gave an error.

Sevre sided with remote

	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)
			local player2 = plr
			if player1 and player2 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
				remote:FireClient(plr, player1, player2)
			end
		end
	end)
end)

remote.OnServerEvent:Connect(function(player, player1, player2)
	remote:FireClient(player, player1, player2)
end)

Client with remote

local remote = game.ReplicatedStorage.UIRemotes.message

local function cloneMessage(clone, player1, player2, isPlayer1)
	local playerIndex = Instance.new("StringValue", clone)
	playerIndex.Name = "sendTo"
	
	if isPlayer1 then
		clone.UserMessage.Text = script.Parent.Text
		clone.From.Text = "Message from " .. player1.Name
		clone.Visible = true
		clone.Parent = player2.PlayerGui.ScreenGui.ScrollingFrame
		playerIndex.Value = player2.Name
		script.Parent.Parent:Destroy()
	else
		clone.UserMessage.Text = script.Parent.Text
		clone.From.Text = "Message from " .. player2.Name
		clone.Visible = true
		clone.Parent = player1.PlayerGui.ScreenGui.ScrollingFrame
		playerIndex.Value = player1.Name
		script.Parent.Parent:Destroy()
	end
	
	return clone, playerIndex.Value 
end

remote.OnClientEvent:Connect(function(player1, player2)
	print(player1)
	print(player2)
	if player1 and player2 then
		print("test")
		script.Parent.FocusLost:Connect(function(enterPressed)
			print("focus lost")
			if enterPressed then
				print("Pressed")
				local clonedMessage = script.Parent.Parent:Clone()
				remote:FireServer(player1, player2)
				
				if script.Parent:IsDescendantOf(player1) then
					print("pressed, player1")
					cloneMessage(clonedMessage, player1, player2, true)
				elseif script.Parent:IsDescendantOf(player2) then
					print("pressed, player2")
					cloneMessage(clonedMessage, player1, player2, false)
				end
			end
		end)
	end
end)

Same issue