What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve looked all over the DevForum and have found absolutely nothing, I’ve ran print statements to ensure that nothing stops the code and nothing appears to be stopping it besides the value turning nil randomly
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- Server Script
ReplicatedStorage.Remotes.NamePicked.OnServerEvent:Connect(function(Player : Player, Action, ChosenName, GUI)
local TextService = game:GetService("TextService")
local Slot = Slots[Player.UserId]["Slot"]
repeat
task.wait()
until GUI
local Overlay = GUI:FindFirstChild("Overlay")
local Confirm = Overlay:WaitForChild("Confirm")
local Warn = Overlay:WaitForChild("Warn")
local CharacterData = DataStoreModule.find("PlayerData", "Player_" .. Player.UserId, Slot)
local FilteredName
if Action == "EnteredName" then
local Success, Result = pcall(TextService.FilterStringAsync, TextService, ChosenName, Player.UserId)
if Success then
FilteredName = Result:GetNonChatStringForBroadcastAsync()
print(FilteredName)
if FilteredName:match("[^a-zA-Z]+") then
Confirm.Visible = false
Warn.Visible = true
task.delay(2, function()
Warn.Visible = false
end)
else
print(FilteredName)
Confirm.Visible = true
end
else
Confirm.Visible = false
Warn.Visible = true
task.delay(2, function()
Warn.Visible = false
end)
end
elseif Action == "FinalizeName" then
GUI:Destroy()
print(FilteredName)
CharacterData.Value.FirstName = FilteredName
print(CharacterData.Value.FirstName)
end
end)
-- Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Overlay = script.Parent:WaitForChild("Overlay")
local TextBox = Overlay.TextBox
local Warn = Overlay.Warn
local Confirm = Overlay.Confirm
TextBox.FocusLost:Connect(function(EnterPressed)
if TextBox.Text ~= "" and (string.len(TextBox.Text) > 3) and (string.len(TextBox.Text) < 12) and EnterPressed then
print(EnterPressed)
Remotes.NamePicked:FireServer("EnteredName", TextBox.Text, script.Parent)
end
end)
Confirm.MouseButton1Click:Connect(function()
if Confirm.Visible == false then
return
else
Remotes.NamePicked:FireServer("FinalizeName", TextBox.Text, script.Parent)
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Each call to the remote event creates a new thread and as filteredname is declared inside the connected function it is a new variable each time.
To fix you just need to move local filteredname to before the remote event connection. Now filteredname will share the same scope with every call to the remoteevent.
Still not ideal as it will change every time any player calls the remote!
So if we convert it to a table
local filterednames ={}
And index it with the player inside the remote event function
filterednames[player] = filteredname
We can keep track of and change everyone’s filteredname
The reason why FilteredName is becoming nil is because you’re doing FilteredName:match(“[^a-zA-Z]+”). If the result is false the name value is being changed to nil so instead of:
if FilteredName:match("[^a-zA-Z]+") then
You need to do something like this:
local textMatchResult = FilteredName:match("[^a-zA-Z]+")
if textMatchResult then
The issue is where FilteredName is nil when you try to print it in the “FinalizeName” action. This is because FilteredName is only defined inside the “EnteredName” action branch.
you need to define FilteredName outside the scope of the “EnteredName” branch so that it is accessible later in the “FinalizeName” branch.
Server script:
ReplicatedStorage.Remotes.NamePicked.OnServerEvent:Connect(function(Player, Action, ChosenName, GUI)
local TextService = game:GetService("TextService")
local Slot = Slots[Player.UserId]["Slot"]
repeat
task.wait()
until GUI
local Overlay = GUI:FindFirstChild("Overlay")
local Confirm = Overlay:WaitForChild("Confirm")
local Warn = Overlay:WaitForChild("Warn")
local CharacterData = DataStoreModule.find("PlayerData", "Player_" .. Player.UserId, Slot)
local FilteredName
if Action == "EnteredName" then
local Success, Result = pcall(TextService.FilterStringAsync, TextService, ChosenName, Player.UserId)
if Success then
FilteredName = Result:GetNonChatStringForBroadcastAsync()
print(FilteredName)
if FilteredName:match("[^a-zA-Z]+") then
Confirm.Visible = false
Warn.Visible = true
task.delay(2, function()
Warn.Visible = false
end)
else
print(FilteredName)
Confirm.Visible = true
end
else
Confirm.Visible = false
Warn.Visible = true
task.delay(2, function()
Warn.Visible = false
end)
end
elseif Action == "FinalizeName" then
GUI:Destroy()
if FilteredName then
print(FilteredName)
CharacterData.Value.FirstName = FilteredName
print(CharacterData.Value.FirstName)
else
warn("FilteredName is nil. Please choose another name.")
end
end
end)
Local Script:
-- Local Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Overlay = script.Parent:WaitForChild("Overlay")
local TextBox = Overlay.TextBox
local Warn = Overlay.Warn
local Confirm = Overlay.Confirm
TextBox.FocusLost:Connect(function(EnterPressed)
if TextBox.Text ~= "" and (string.len(TextBox.Text) > 3) and (string.len(TextBox.Text) < 12) and EnterPressed then
print(EnterPressed)
Remotes.NamePicked:FireServer("EnteredName", TextBox.Text, script.Parent)
end
end)
Confirm.MouseButton1Click:Connect(function()
if Confirm.Visible == false then
return
else
Remotes.NamePicked:FireServer("FinalizeName", TextBox.Text, script.Parent)
end
end)
Not possible, You cannot change the Players name as it won’t change in “Players” service even if you get the Characters model Name to change still won’t work.
I just saw this, for some reason it didn’t appear until I refreshed and scrolled up. It did end out working, I didn’t realize that the table refreshes everytime the event is called