Help with text formatting in DataStores

Hello!

I am making a support system, and I want my administrators to be able to write with leading (space between lines). So when they press enter, a line break is added, and it gets saved to a datastore. However when they load it in, I still want the line breaks to be there.

How should I think when implementing this?

add \n to the string when they press enter

Turn on MultiLine in your TextBox so that players can add linebreaks

Then, to check whenever a new line is added:
You first listen to changes in the text

TextBox:GetPropertyChangedSignal("Text"):Connect(function(newText)
end)

then you only use the characters in the new text that have been newly added, by keeping track of the old text and using string.sub

local oldText = TextBox.Text
TextBox:GetPropertyChangedSignal("Text"):Connect(function(newText)
        local oldTextLength = #oldText
        if oldTextLength < #newText then
                local newlyAddedCharacters = string.sub(newText, oldTextLength)
        end
        
        oldText = newText
end)

with that, you check if a newline is anywhere in the newly added characters, and if so, you just ask the server to save all the text

if string.find(newlyAddedCharacters, "\n") ~= nil then
        -- Ask server to save text
end

Thanks!

I think it’ll work!

(characters)