Hi, I want to make a music gui, and I’m using a textbox, but I don’t know how to make a limiter for the characters, I tried to use two different Local Script, one for the real script and the second one for the limiter, but the game on phone lag a lot, so how can I do ?
First Local Script
TextBox.Changed:Connect(function()
local Car1 = workspace.PlayersFolder:FindFirstChild(LocalPlayer.Name):WaitForChild("Car5", 1)
local Audio = Car1.Body.Music.MusicAudio
Audio.SoundId = "rbxassetid://"..TextBox.Text
end)
I forgot to mention to add a debounce since changing the text still fires the event:
local maxCharacters = 10
local debounce = true
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
if debounce then
debounce = false
TextBox.Text = TextBox.Text:gsub("%D+", ""):sub(1, maxCharacters)
debounce = true
end
end)
ok now I changed the scirpt like this but if I use the phone the game lag when I try to delete what I write
local MusicGUI = script.Parent.Parent.MusicGUI
local TextBox = MusicGUI.TextBox
local PlayButton = MusicGUI.PlayButton
local LocalPlayer = game:GetService("Players").LocalPlayer
local Car1 = workspace.PlayersFolder:FindFirstChild(LocalPlayer.Name):WaitForChild("Car5", 1)
local Audio = Car1.Body.Music.MusicAudio
TextBox.Changed:Connect(function()
local maxCharacters = 10
local debounce = true
if debounce then
debounce = false
TextBox.Text = TextBox.Text:gsub("%D+", ""):sub(1, maxCharacters)
Audio.SoundId = "rbxassetid://"..TextBox.Text
debounce = true
end
end)