Hey everyone!
I’m trying to make a grammar fixer so that when someone forgets to use punctuation or capitalize their sentences it will automatically fix the message for them. Currently, I am just re sending the corrected message, but I was wondering if there was a way to edit the original message. Here is my current code.
local ChatS = game:GetService('Chat')
local function split(s,d)
d = d or ' ';
local t = {};
s:gsub('([^'..d..']+)',function(c) t[#t+1] = c end);
return t;
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Player.Chatted:Connect(function(Message)
local fromPlayerId = Player
local lastletter = string.sub(Message, -1)
local firstletter = string.sub(Message,1,1)
local restofmessage = string.sub(Message, 2, string.len(Message))
local SplitMessage = split(Message)
--if #SplitMessage >= 2 then
if lastletter ~= "." and lastletter ~= "!" and lastletter ~= "?" then
wait(0.5)
if string.upper(firstletter) ~= firstletter then
local NewMessage = string.upper(firstletter) .. restofmessage .. ".*"
local filteredTextResult = ChatS:FilterStringForBroadcast(NewMessage, fromPlayerId)
print(filteredTextResult)
if string.sub(filteredTextResult, -1) ~= "#" or string.sub(filteredTextResult, 1,1) ~= "#" then
ChatS:Chat(Character, filteredTextResult, "White")
end
else
if #SplitMessage >= 2 then
local NewMessage = Message .. ".*"
local filteredTextResult = ChatS:FilterStringForBroadcast(NewMessage, fromPlayerId)
if string.sub(filteredTextResult, -1) ~= "#" then
ChatS:Chat(Character, filteredTextResult, "White")
end
end
end
elseif string.upper(firstletter) ~= firstletter then
local NewMessage = string.upper(firstletter) .. restofmessage .. "*"
local filteredTextResult = ChatS:FilterStringForBroadcast(NewMessage, fromPlayerId)
if string.sub(filteredTextResult, 1,1) ~= "#" then
ChatS:Chat(Character, filteredTextResult, "White")
end
end
--end
end)
end)
end)
Thanks everyone!