Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

RP Name Fitler Help? For a Roleplay Game. Where do i get a filter!

So me and my friend work on a roleplay game right? Every roleplay game needs names. i need help getting a filter for my Friends RP name script if anyone could help thank you!

local Game 						= Game
local Workspace					= Workspace
local Players					= Game:GetService('Players')
local DataStore					= Game:GetService('DataStoreService'):GetDataStore('Nameplates')
local HttpService				= Game:GetService('HttpService')
local RbxUtility = require(game:GetService("ReplicatedStorage"):
    WaitForChild("LoadLibrary"):WaitForChild("RbxUtility"))
local Commands					= require(script:WaitForChild('Commands'))
--
local MaxCharacters				= 150
--
local function Color3ToString(Color)
	return math.floor(Color.r*255)..' '..math.floor(Color.g*255)..' '..math.floor(Color.b*255)
end

local function StringToColor3(String)
	local Pos = 1
	local Values = {}
	for Value in string.gmatch(String, "%S+") do
    	Values[Pos] = (tonumber(Value) / 255)
		Pos = Pos + 1
	end
	return Color3.new(Values[1],Values[2],Values[3])
end
--
local function GetCharacter(Player)
	if not Player.Character then
		repeat wait() until Player.Character
	end
	return Player.Character
end

local function GetNameplate(Character)
	local Head = Character:WaitForChild('Head')
	return Head:WaitForChild('Nameplate')
end

local function UpdateNameplate(Player)
	local Info = Player.NameplateInfo
	local Character = GetCharacter(Player)
	local Nameplate = GetNameplate(Character).Title
	Nameplate.Text = Info.PlayerName.Value
	Nameplate.TextColor3 = Info.Color.Value
	Nameplate.Font = Info.Font.Value
end

local function SaveNameplate(Player)
	local Key = Player.UserId
	local Info = Player.NameplateInfo
	local Data = {}
	for _,DataValue in next, Info:GetChildren() do
		if DataValue.Name == 'Color' then
			Data[DataValue.Name] = Color3ToString(DataValue.Value)
		else
			Data[DataValue.Name] = DataValue.Value
		end
	end
	DataStore:SetAsync(Key,HttpService:JSONEncode(Data))
end

local function LoadNameplate(Player)
	local Key = Player.UserId
	local Info = Player.NameplateInfo
	local Data = HttpService:JSONDecode(DataStore:GetAsync(Key))
	if Data then
		for _,iValue in next, Info:GetChildren() do
			for dName,dValue in next, Data do
				if iValue.Name == dName then
					if dName == 'Color' then
						dValue = StringToColor3(dValue)
					end
					iValue.Value = dValue
				end
			end
		end
		UpdateNameplate(Player)
	end
end
--
local function Chatted(Player,Message)
	for Name,Command in next, Commands do
		local Length = (Message:find(' ') or (Message:len() + 1)) - 1
		local TypedCommand = Message:sub(1,Length)
		if TypedCommand == '/'..Name then
			local Argument = (Message:sub(Length + 2)) or nil
			if Argument and Argument:len() > MaxCharacters then
				Argument = Argument:sub(1,MaxCharacters)
			end
			Commands[Name](GetNameplate(GetCharacter(Player)),Argument)
		end
	end
end

local function CharacterAdded(Character)
	local Player = Players:GetPlayerFromCharacter(Character)
	local Info = Player.NameplateInfo
	--
	wait(0.1)
	--
	local BillboardGui = RbxUtility.Create('BillboardGui') {
		Name = 'Nameplate',
		Parent = Character:WaitForChild('Head'),
		AlwaysOnTop = true,
		Size = UDim2.new(0,1,0,1),
		StudsOffset = Vector3.new(0,2,0),
	}
	local Title = RbxUtility.Create('TextLabel') {
		Name = 'Title',
		Parent = BillboardGui,
		BorderSizePixel = 0,
		Size = UDim2.new(0,1,0,1),
		Font = Info.Font.Value,
		FontSize = 'Size18',
		Text = Info.PlayerName.Value,
		TextColor3 = Info.Color.Value,
		TextStrokeTransparency = 0.8,
	}
end

local function PlayerAdded(Player)
	local NameplateInfo = RbxUtility.Create('Configuration') {
		Name = 'NameplateInfo',
		Parent = Player,
	}
	local NameInfo = RbxUtility.Create('StringValue') {
		Name = 'PlayerName',
		Parent = NameplateInfo,
		Value = Player.Name,
	}
	local ColorInfo = RbxUtility.Create('Color3Value') {
		Name = 'Color',
		Parent = NameplateInfo,
		Value = Color3.new(1,1,1),
	}
	local FontInfo = RbxUtility.Create('StringValue') {
		Name = 'Font',
		Parent = NameplateInfo,
		Value = 'ArialBold',
	}
	Player.CharacterAdded:connect(CharacterAdded)
	Player.Chatted:connect(function(Message) Chatted(Player,Message) end)
	LoadNameplate(Player)
end

local function PlayerRemoving(Player)
	SaveNameplate(Player)
end

Players.PlayerAdded:connect(PlayerAdded)
Players.PlayerRemoving:connect(PlayerRemoving)

Forgot to post the commands! Sorry PPL!

local ValidFonts = {'Arial','ArialBold','Legacy','SourceSans','SourceSansBold','SourceSansLight','SourceSansItalic'}

local function GetTitle(Nameplate)
	return Nameplate:FindFirstChild('Title')
end

local function GetPlayerFromNameplate(Nameplate)
	local Character = Nameplate.Parent.Parent
	return game.Players:GetPlayerFromCharacter(Character)
end

return {
	['hide'] = function(Nameplate)
		Nameplate.Enabled = false
	end,
	
	['show'] = function(Nameplate,Font)
		Nameplate.Enabled = true
	end,
	
	['color'] = function(Nameplate,Color)
		local Title = GetTitle(Nameplate)
		if Title then
			local Player = GetPlayerFromNameplate(Nameplate)
			local Info = Player:FindFirstChild('NameplateInfo')
			if Info then
				Info.Color.Value = BrickColor.new(Color).Color
				Title.TextColor3 = BrickColor.new(Color).Color
			end
		end
	end,
	
	['name'] = function(Nameplate,Name)
		local Title = GetTitle(Nameplate)
		if Title then
			local Player = GetPlayerFromNameplate(Nameplate)
			local Info = Player:FindFirstChild('NameplateInfo')
			if Info then
				Info.PlayerName.Value = Name
				Title.Text = Name
			end
		end
	end,
	
	['font'] = function(Nameplate,Font)
		local Title = GetTitle(Nameplate)
		if Title then
			local Player = GetPlayerFromNameplate(Nameplate)
			local Info = Player:FindFirstChild('NameplateInfo')
			if Info then
				for _,FontName in next, ValidFonts do
					if Font == FontName then
						Info.Font.Value = Font
						Title.Font = Font
					end
				end
			end
		end
	end,
}

1 comment

1

This is so deprecated;; you can use TextService to do that.

1 answer

First, you are using :connect wich is deprecated and may break your scripts later. Second, you are using RbxUtility instead of Instance.new wich doesn't has much sense to it but I guess that's what you want.

So to filter it you could use FilterStringForBroadcast function.

So implementing this to your code ends in this.

local Game                      = Game
local Workspace                 = Workspace
local Players                   = Game:GetService('Players')
local DataStore                 = Game:GetService('DataStoreService'):GetDataStore('Nameplates')
local HttpService               = Game:GetService('HttpService')
local RbxUtility = require(game:GetService("ReplicatedStorage"):
    WaitForChild("LoadLibrary"):WaitForChild("RbxUtility"))
local Commands                  = require(script:WaitForChild('Commands'))
--
local MaxCharacters             = 150
--

local function filter(String,From)

local filteredString = game.Chat:FilterStringForBroadcast(String,From)

-- You could add more stuff if you want

return filteredString

end

local function Color3ToString(Color)
    return math.floor(Color.r*255)..' '..math.floor(Color.g*255)..' '..math.floor(Color.b*255)
end

local function StringToColor3(String)
    local Pos = 1
    local Values = {}
    for Value in string.gmatch(String, "%S+") do
        Values[Pos] = (tonumber(Value) / 255)
        Pos = Pos + 1
    end
    return Color3.new(Values[1],Values[2],Values[3])
end
--
local function GetCharacter(Player)
    if not Player.Character then
        repeat wait() until Player.Character
    end
    return Player.Character
end

local function GetNameplate(Character)
    local Head = Character:WaitForChild('Head')
    return Head:WaitForChild('Nameplate')
end

local function UpdateNameplate(Player)
    local Info = Player.NameplateInfo
    local Character = GetCharacter(Player)
    local Nameplate = GetNameplate(Character).Title
    Nameplate.Text = filter(Info.PlayerName.Value,Player) --// Our function
    Nameplate.TextColor3 = Info.Color.Value
    Nameplate.Font = Info.Font.Value
end

local function SaveNameplate(Player)
    local Key = Player.UserId
    local Info = Player.NameplateInfo
    local Data = {}
    for _,DataValue in next, Info:GetChildren() do
        if DataValue.Name == 'Color' then
            Data[DataValue.Name] = Color3ToString(DataValue.Value)
        else
            Data[DataValue.Name] = DataValue.Value
        end
    end
    DataStore:SetAsync(Key,HttpService:JSONEncode(Data))
end

local function LoadNameplate(Player)
    local Key = Player.UserId
    local Info = Player.NameplateInfo
    local Data = HttpService:JSONDecode(DataStore:GetAsync(Key))
    if Data then
        for _,iValue in next, Info:GetChildren() do
            for dName,dValue in next, Data do
                if iValue.Name == dName then
                    if dName == 'Color' then
                        dValue = StringToColor3(dValue)
                    end
                    iValue.Value = dValue
                end
            end
        end
        UpdateNameplate(Player)
    end
end
--
local function Chatted(Player,Message)
    for Name,Command in next, Commands do
        local Length = (Message:find(' ') or (Message:len() + 1)) - 1
        local TypedCommand = Message:sub(1,Length)
        if TypedCommand == '/'..Name then
            local Argument = (Message:sub(Length + 2)) or nil
            if Argument and Argument:len() > MaxCharacters then
                Argument = Argument:sub(1,MaxCharacters)
            end
            Commands[Name](GetNameplate(GetCharacter(Player)),Argument)
        end
    end
end

local function CharacterAdded(Character)
    local Player = Players:GetPlayerFromCharacter(Character)
    local Info = Player.NameplateInfo
    --
    wait(0.1)
    --
    local BillboardGui = RbxUtility.Create('BillboardGui') {
        Name = 'Nameplate',
        Parent = Character:WaitForChild('Head'),
        AlwaysOnTop = true,
        Size = UDim2.new(0,1,0,1),
        StudsOffset = Vector3.new(0,2,0),
    }
    local Title = RbxUtility.Create('TextLabel') {
        Name = 'Title',
        Parent = BillboardGui,
        BorderSizePixel = 0,
        Size = UDim2.new(0,1,0,1),
        Font = Info.Font.Value,
        FontSize = 'Size18',
        Text = Info.PlayerName.Value,
        TextColor3 = Info.Color.Value,
        TextStrokeTransparency = 0.8,
    }
end

local function PlayerAdded(Player)
    local NameplateInfo = RbxUtility.Create('Configuration') {
        Name = 'NameplateInfo',
        Parent = Player,
    }
    local NameInfo = RbxUtility.Create('StringValue') {
        Name = 'PlayerName',
        Parent = NameplateInfo,
        Value = Player.Name,
    }
    local ColorInfo = RbxUtility.Create('Color3Value') {
        Name = 'Color',
        Parent = NameplateInfo,
        Value = Color3.new(1,1,1),
    }
    local FontInfo = RbxUtility.Create('StringValue') {
        Name = 'Font',
        Parent = NameplateInfo,
        Value = 'ArialBold',
    }
    Player.CharacterAdded:Connect(CharacterAdded)
    Player.Chatted:Connect(function(Message) Chatted(Player,Message) end)
    LoadNameplate(Player)
end

local function PlayerRemoving(Player)
    SaveNameplate(Player)
end

Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)

If this answered your question accept it! It would be highly appreciated.

12 comments

0

i need help with the commands now the name wont work after typing /name anything here

0

let me do it

0

errors?

0

well my friend has this weird chat in his game so idk if that has to do with it

0

check developer console

0

oh i have the solution

0

when setting it use filterstringforbroadcast

0

okay i got the code do i just place it in chat or no

0

put it on the script that had the problem

0

kk

0

it doesnt show whihc one is having probelms when i open it up so thats great...

0

i am waiting to see if anything happens but so far ntohing

This discussion is preserved as it was. New answers, comments, and votes are closed.