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

Why won't the filtering work and why won't the text color change?

Asked by 5 years ago
Edited 5 years ago

Why won't the filtering work and why won't the text color change? Please help?

local RepStorage = game:GetService("ReplicatedStorage")
local Remote = RepStorage:WaitForChild("BasicNametagRemote")
local TextService = game:GetService("TextService")

Remote.OnServerEvent:Connect(function(player, NameChoice, ColorChoice)
    local NameFilteredChoice = TextService:FilterStringAsync(NameChoice, player.UserId)
    local PlayerName = player.name
    local Nametag = game.ReplicatedStorage.CloneableObjects.Nametag:Clone()
    Nametag.Parent = game.Workspace[PlayerName].Head
    Nametag.NameLabel.Text = NameChoice
    Nametag.NameLabel.TextColor3 = BrickColor.new(NameFilteredChoice)
end)

Error: ServerScriptService.BasicNametagCreator:11: bad argument #1 to 'new' (Color3 expected, got Object)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Your using BrickColor.new, so it will error since your accessing the Color3 value of the part. Just use Color3.new instead. Its also suggested to use Color3.fromRGB since it uses Red, Green and Blue unlike Color3.new which you need to divide by 255.

local RepStorage = game:GetService("ReplicatedStorage")
local Remote = RepStorage:WaitForChild("BasicNametagRemote")
local TextService = game:GetService("TextService")

Remote.OnServerEvent:Connect(function(player, NameChoice, ColorChoice)
    local NameFilteredChoice = TextService:FilterStringAsync(NameChoice, player.UserId)
    local PlayerName = player.name
    local Nametag = game.ReplicatedStorage.CloneableObjects.Nametag:Clone()
    Nametag.Parent = game.Workspace[PlayerName].Head
    Nametag.NameLabel.Text = NameChoice
    Nametag.NameLabel.TextColor3 = Color3.fromRGB( a Color3 value)
end)

though if your NameFilteredChoice parameter is a BrickColor then you need to switch it to a Color3 value.

0
Color3.new still uses red, green, and blue; it just takes a value between 0 and 1 rather than 0 and 255. (0 to 1 can be better in some cases: for example, if you want to turn a math.random() into a color.) User#22604 1 — 5y
Ad

Answer this question