Hello there. Today I'm working on a custom chat system. The game is using FilteringEnabled so I'm using remote events to organize responses from the client and server. The problem is that I've somehow created a loop with the RemoteEvents that outputs what I need and causes more loops. Those loops cause more loops and so on giving me more and more results I don't need. Here's all the applicable code I can think to add:
LocalScript
game.Players.LocalPlayer:WaitForChild("ClientUpdateMsgSizeEvent").OnClientEvent:connect(function(SentMsgNumber)
wait(1)
local MsgToCheck = RegChatDisplay:WaitForChild("Message"..SentMsgNumber)
MsgToCheck.Size = MsgToCheck.Size + UDim2.new(0, 0, 0, 18)
local PreviousMsgs = RegChatDisplay:GetChildren()
for i = 1, #PreviousMsgs do
wait(1)
print("This should run "..#PreviousMsgs.." times.")
PreviousMsgs[i].Position = PreviousMsgs[i].Position - UDim2.new(0, 0, 0, 18)
end
CheckMsgLength(SentMsgNumber)
end)
function CheckMsgLength(SentMsgNumber)
local MsgToCheck = "Message to check"
MsgToCheck = RegChatDisplay:WaitForChild("Message"..SentMsgNumber)
wait(.1)
if MsgToCheck.TextFits == false then
wait(1)
game.Workspace.ServerUpdateMsgSizeEvent:FireServer(SentMsgNumber)
elseif MsgToCheck.TextFits == true then
print("The text now fits. Do not repeat")
else
error("Somthing went wrong here")
end
end
ServerScript
local ServerUpdateMsgSizeEvent = Instance.new("RemoteEvent")
ServerUpdateMsgSizeEvent.Name = "ServerUpdateMsgSizeEvent"
ServerUpdateMsgSizeEvent.Parent = game.Workspace
game.Players.PlayerAdded:connect(function(player)
local ClientUpdateMsgSizeEvent = Instance.new("RemoteEvent")
ClientUpdateMsgSizeEvent.Name = "ClientUpdateMsgSizeEvent"
ClientUpdateMsgSizeEvent.Parent = player
ServerUpdateMsgSizeEvent.OnServerEvent:connect(function(Player,SentMsgNumber )
wait(1)
ClientUpdateMsgSizeEvent:FireClient(player,SentMsgNumber)
end)
end)
The "wait(1)"s are just there to slow down the process and can be ignored.
Any help you guys can provide is appreciated.

1 comment
I guess I'm still rather confused. I'd like the loop to continue until the TextFits statement returns true, but that's not happening. The loop doesn't stop once TextFits == true. I am using two remote events for server and client-side operations. Could you elaborate some more? Thanks