I am attempting to find more than one character in a string. I was thinking of using string.match() but I don't think that's right.
I need a function that will find the characters that I put in in a string.
I need to match a space, a comma, a period, a question mark, and an exclamation mark, but I don't want to use %p in my code because that gets all punctuations and I just want those ones.
In my code, if I type in a punctuation or a space and type normal characters, the output still says that I typed a punctuation or space.
Example text that I wrote into my script: "Hello, this is text!"
Output:
You pressed enter
wasn't punctuation or space so it played sound (x5)
was a punctuation or a space so it didn't play sound (x15)
Here's the code I'm attempting:
local sound = game.SoundService:WaitForChild("KeyboardSound")
local writeBox = script.Parent
local autoWriteBox = writeBox.Parent:WaitForChild("AutoWriteBox")
script.Parent.FocusLost:Connect(function(ep, iTCFL) --bool enterPressed, inputThatCausedFocusLoss
if ep then
print("You pressed enter")
for i = 1, #writeBox.Text, 1 do
autoWriteBox.Text = string.sub(writeBox.Text, 1, i)
local match = string.match(string.sub(writeBox.Text, 1, i), "[%p%s]+") -- what can I change?
if match == nil then
print("wasn't punctuation or space so it played sound")
game.SoundService:PlayLocalSound(sound)
else
print("was a punctuation or a space so it didn't play sound ")
end
wait(0.1)
end
end
end)
