I wanted to achieve requiring players to have an “@” symbol at the start of the text inside of text box for more clarification here is an example:
Inside of a text users are required to put there username inside of it but, at the first of the name it needed something like “@” (ex: @UserAsync) if the symbol is not entered it will show an error messege
local ourstring = "Hello @itzmevonkarl1234!"
if not string.find(ourstring,"@") then
print("Nope")
end
Or
local ourstring = "@itzmevonkarl1234, @Crypt1lc"
local split = ourstring:split(" ")
for i,v in pairs(split) do
if not v:sub(1,1) == "@" then
print("Nope")
end
end
Explaination:
First code sees if there is any @ in a string. We use string.find to do that and then using an if statement we compute our response
Second code sees if there is a @ symbol in each word at the start. Using split we split all the words then using string.sub we get the first letter of said string.
local Players = game:GetService("Players")
local textBox = script.Parent
local player = Players.LocalPlayer
local requiredText = "@"..player.Name -- You can replace this with "@"..player.DisplayName too if you prefer
local function onFocusLost(enterPressed)
if enterPressed then
if string.find(textBox.Text, requiredText) then
print("Success!")
else
warn("Fail!")
end
end
end
textBox.FocusLost:Connect(onFocusLost)
Although if the username must always be at the very start of the text, you’ll need to do this instead:
local Players = game:GetService("Players")
local textBox = script.Parent
local player = Players.LocalPlayer
local requiredText = "@"..player.Name -- You can replace this with "@"..player.DisplayName too if you prefer
local function onFocusLost(enterPressed)
if enterPressed then
local index = string.find(textBox.Text, requiredText)
if index and index == 1 then
print("Success!")
else
warn("Fail!")
end
end
end
textBox.FocusLost:Connect(onFocusLost)
To be honest though, an example would be very helpful for us to understand what you’d like the end result to look like