Best way to implement custom roleplay names?

Saying your full name can actually get you banned on Roblox for giving out personal information, Even if a word is unfairly filtered don’t bypass.

This thread never really got a proper solution so here you go.

--LOCAL

local replicated = game:GetService("ReplicatedStorage")
local remote = replicated:WaitForChild("RemoteEvent")
local screenGui = script.Parent
local frame = screenGui:WaitForChild("Frame")
local textBox = frame:WaitForChild("TextBox")
textBoxTextChanged = textBox:GetPropertyChangedSignal("Text")
local textButton = frame:WaitForChild("TextButton")

local function onTextBoxTextChanged()
	textBox.Text = string.gsub(textBox.Text, "_?(.*)_?", "%1")
	textBox.Text = string.gsub(textBox.Text, "[%W_]", "") --Adheres to the characters allowed in usernames on Roblox.
end

local function onTextButtonClicked()
	local textLength = string.len(textBox.Text)
	if textLength < 3 or textLength > 20 then return end --Adheres to Roblox's username length rules.
	remote:FireServer(textBox.Text)
end

textBoxTextChanged:Connect(onTextBoxTextChanged)
textButton.MouseButton1Click:Connect(onTextButtonClicked)
--SERVER

local replicated = game:GetService("ReplicatedStorage")
local remote = replicated.RemoteEvent
local texts = game:GetService("TextService")
local filterString = texts.FilterStringAsync

local function onRemoteFired(player, text)
	if not player.Parent then return end
	local character = player.Character
	if not character then return end
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then return end
	if humanoid.Health <= 0 then return end
	local success, result = pcall(filterString, texts, text, player.UserId)
	if success then
		if result then
			local getNonChatStringForBroadcast = result.GetNonChatStringForBroadcastAsync
			local success2, result2 = pcall(getNonChatStringForBroadcast, result)
			if success2 then
				if result2 then
					humanoid.DisplayName = result2
				end
			else
				warn(result2)
			end
		end
	else
		warn(result)
	end
end

remote.OnServerEvent:Connect(onRemoteFired)

rpnames.rbxl (36.4 KB)

1 Like