Hello, I have a problem with strings.
I made my own chat in which everything works fine except this part: I made a script that only let’s 25 characters on each line so if you type something that is 25+ characters it will be split, just so it prevents the text from getting very small.
Example
“BawTheSeal: Less than 25 chars” -first message
“BawTheSeal: More than 25 (continuous a’s)” -second message
The problem is that some words get cut off or removed, example:
String = “Hello, my name is Baw and I’m here to tell you that you are amazing.”
Chat:
As you can see it has cut off and removed some words (name,is,baw,and) and if you look at the word “that” it duplicated the a.
Script:
local ChatStorage = game.Workspace.ChatStorage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("FiredChat")
local remoteEventTxt2Long = ReplicatedStorage:WaitForChild("MsgTooLong")
remoteEvent.OnServerEvent:Connect(function(plr,msg)
local user = plr.Name..": "
if msg:len() >= 25 then
local stringval = Instance.new("StringValue",ChatStorage)
stringval.Name = user..string.sub(msg,1,25 - user:len())
local stringval2 = Instance.new("StringValue",ChatStorage)
stringval2.Name = string.sub(msg,25,50)
if stringval2.Name:len() >= 25 then
local stringval3 = Instance.new("StringValue",ChatStorage)
stringval3.Name = string.sub(msg,50,75)
if stringval3.Name:len() >= 25 then
remoteEventTxt2Long:FireClient(plr)
end
end
else
local stringval = Instance.new("StringValue",ChatStorage)
stringval.Name = plr.Name..": "..msg
end
end)
Is there a way to accomplish it not cutting off,removing or duplicating words?
Note: I am very new to strings so, sorry if the answer is a really easy thing, string.sub is the only function i know that removes characters.