Hello, this is my first time posting something on the Roblox Developer Forum so if I’ve done something wrong then tell me the right thing to do.
I was working on a model and I want it to send a message everytime a player writes on the GUI and clicks the send button.
I encountered 2 issues in my code and I don’t know how to fix them.
First: If there are for example 3 players in the game, when a player clicks the send button the script will send the same message three times instead of one time.
Second: I wanted to put text limits on the TextBox but if someone copies and pastes a large amount of text I get an error in the output that says “Maximum event re-entrancy depth exceeded for Instance.TextChanged”.
The scripts:
ServerScript
local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.SendMessageToAllClients
local CooldownScript = require(script.Parent.Parent.CooldownBox.Bar.CooldownScript)
local FilteredText = ""
local FilteredTextResult
RemoteEvent.OnServerEvent:Connect(function(Player, Argument)
if Argument == "ERRLIMIT0022020" then
script.Parent.Parent.ErrorBox.Text = "The number of characters exceeds the limit of 100."
elseif Argument == "ERRCOOLDOWN20020200" then
script.Parent.Parent.ErrorBox.Text = "Please wait until the cooldown ends."
elseif Argument == "ERRBOUNDS0020020" then
script.Parent.Parent.ErrorBox.Text = "Text cannot exceed the TextBox's bounds."
elseif Argument == "ERRBOUNDS0020200" then
script.Parent.Parent.ErrorBox.Text = "Text deleted due to absolute limit being broken."
elseif Argument == "ERREMPTY0022002" then
script.Parent.Parent.ErrorBox.Text = "Please type something in the TextBox."
else
local Success, ErrorMessage = pcall(function()
FilteredTextResult = TextService:FilterStringAsync(Argument, Player.UserId)
end)
if Success then
script.Parent.Parent.ErrorBox.Text = ""
FilteredText = FilteredTextResult:GetNonChatStringForBroadcastAsync()
RemoteEvent:FireAllClients(Player,FilteredText)
CooldownScript()
elseif ErrorMessage then
script.Parent.Parent.ErrorBox.Text = "An error occurred while filtering text."
end
end
end)
LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local RemoteEvent = ReplicatedStorage.SendMessageToAllClients
local TextBox = script.Parent.Parent.MainTextBox
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.CooldownBox.Bar.CooldownEnabled.Value == true then
RemoteEvent:FireServer("ERRCOOLDOWN20020200")
elseif string.len(TextBox.Text) > 100 then
RemoteEvent:FireServer("ERRLIMIT0022020")
elseif TextBox.Text == "" then
RemoteEvent:FireServer("ERREMPTY0022002")
else
RemoteEvent:FireServer(TextBox.Text)
wait()
TextBox.Text = ""
end
end)
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
if TextBox.TextFits == false then
if string.len(TextBox.Text) > 350 then
TextBox.Text = ""
RemoteEvent:FireServer("ERRBOUNDS0020200")
else
TextBox.Text = TextBox.Text:sub(1, #TextBox.Text - 10)
RemoteEvent:FireServer("ERRBOUNDS0020020")
end
end
end)
RemoteEvent.OnClientEvent:Connect(function(Player, Argument)
local MessageSettings = {
Text = "[Message Machine]: "..(Argument);
}
StarterGui:SetCore("ChatMakeSystemMessage", MessageSettings)
end)
I’m trying to find out how to fix this error, any help will be appreciated.