Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

RP Name FilterStringForBroadcast help please? Thanks!

Asked by 3 years ago

so i got my script now but idk where i need to put FilterStringForBroadcast or how to even make it in the scripts since i am new to scripting this kinda of stuff so please tell me

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)

Commands (just in case)

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,
}

Answer this question