One issue, Phone messaging script sends multiple messages of one message

-- Main Code - Local Script

-- Send messages
local FireEventDeb = false
script.Parent.Send.MouseButton1Click:Connect(function()
    if FireEventDeb == true then return end
    FireEventDeb = true

    if script.Parent.Text == nil or
        script.Parent.Text == "" or
        script.Parent.Text == " " then 
        script.Parent.Text = "MESSAGE CANNOT BE EMPTY" 
        task.wait(1) script.Parent.Text = ""
        else
        local From = templates:WaitForChild("FromMessagesTemplate"):Clone()
        From.Text = script.Parent.Text
        From.Parent = script.Parent.Parent:WaitForChild("Recieve")
        From.Visible = true
        game:GetService("ReplicatedStorage").SendMessage:FireServer(game.Players.LocalPlayer, script.Parent.Text, script.Parent.Parent.Name)
        
        task.wait(0.01)
        script.Parent.Text = ""
    end
    
    task.wait(1)
    FireEventDeb = false
end)

-- Recieve messages
local Deb = false
game:GetService("ReplicatedStorage"):WaitForChild("RecieveMessage").OnClientEvent:Connect(function(From, Message)
    if Deb == true then return end
    Deb = true
    local To = templates:WaitForChild("RecievingMessage"):Clone()
    To.Text = Message
    To.Parent = game.Players.LocalPlayer.PlayerGui.Phone.Frame.Phone.Main.PlayerContacts:FindFirstChild(string.lower(From.Name)).Recieve
    To.Visible = true
    task.wait(2)
    Deb = false
end)

game:GetService("UserInputService").InputBegan:Connect(function()
    if script.Parent:IsFocused() == true then
        game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.3, Enum.EasingStyle.Quint), {BackgroundColor3 = Color3.fromRGB(24, 116, 255)}):Play()
        else
        game:GetService("TweenService"):Create(script.Parent, TweenInfo.new(0.3, Enum.EasingStyle.Quint), {BackgroundColor3 = Color3.fromRGB(23, 23, 23)}):Play()
    end
end)

– Server script (Send messages and filter)

local TextService = game:GetService("TextService")

local function getTextObject(message, fromPlayerId)
    local textObject
    local success, errorMessage = pcall(function()
        textObject = TextService:FilterStringAsync(message, fromPlayerId)
    end)
    if success then
        return textObject
    else
        warn(errorMessage)
    end
    return false
end

local function getFilteredMessage(textObject, toPlayerId)
    local filteredMessage
    local success, errorMessage = pcall(function()
        filteredMessage = textObject:GetChatForUserAsync(toPlayerId)
    end)
    if success then
        return filteredMessage
    else
        warn(errorMessage)
    end
    return false
end

RS:WaitForChild("SendMessage").OnServerEvent:Connect(function(Player, From, Message, To)
    if Message == "" then
        return
    end

    local messageObject = getTextObject(Message, From.UserId)
    if not messageObject then
        return
    end

    local filteredMessage = getFilteredMessage(messageObject, From.UserId)
    RS:WaitForChild("RecieveMessage"):FireClient(game:GetService("Players"):FindFirstChild(To), From, filteredMessage)
end)

The issues is that the messages keep sending multiple times if not twice.

2 Likes