Hi,for my game i need a string preview to make player experiencer easier.
Roblox (gyazo.com) (i want somehting like that it from Grand Piece Online)
can someone explain what i have to use i think string:sub() but idk how. Have a nice day.
Hi,for my game i need a string preview to make player experiencer easier.
Roblox (gyazo.com) (i want somehting like that it from Grand Piece Online)
can someone explain what i have to use i think string:sub() but idk how. Have a nice day.
i think you can just copy another text in the back of it with lower z-index and change the text of it
string.find(PlayerName:sub(1, Input:len()):lower(), Input:lower())
This will try to check if your user’s input matches the beginning of a player’s name.
Let’s say your PlayerName is “Foufou” and you type “fou”:
Input:len() --> 3 (length of input, "fou")
-- get the part of the string between indexes 1 and 3
PlayerName:sub(1, Input:len()) --> "Fou" since that's the first 3 letters of the player's name
-- then use :lower() to convert string to lowercase because "Fou" will not match "fou"
-- and finally use string.find() or :find() to check if input matches player name
Your code can look something like this:
local Players = game:GetService'Players'
TextBox:GetPropertyChangedSignal'Text':Connect(function()
local Input = TextBox.Text:lower()
for i, Player in pairs(Players:GetPlayers()) do
if string.find(Player.Name:sub(1, Input:len()):lower(), Input) then
AutoComplete.Text = Player.Name
end
end
end)
To actually display the autocompleted text on your text box like in the gif you can probably use the method from the reply above
you could also use string.match, that way we could allow stuff like " fou "
also it is GetPropertyChangedSignal not GetPropertyChanged
local Players = game:GetService("Players")
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
local Input = textbox.text:lower():match("^%s*(.-)%s*$")
for _, Player in ipairs(Players:GetPlayers()) do
if Player.Name:lower():match("^"..Input) then
AutoComplete.Text = Player.Name
end
end
end)
Ty, and
print(("foufou"):match("^%s* fou %s*"))
doesn’t seem to work
Also I don’t see a difference between find
or match
for this use case, you can use string patterns in string.find
too
my bad I fixed it
CODE EDIT:
I realized it didn’t work again so I changed "%s*(.*)%s*"
to "^%s*(.-)%s*$"
and that fixed it
I wasn’t talking about the use of string.find, I was talking about string.sub being used
Thanks you guys for you quick answer.