Hi! I have this script in datastore that when the specified remote event is triggered, the style is either bought or equipped. The buying part is fine but the problem is the equipping part, specifically setting the player’s nametag to a specific color. Here is my script:
StyleSelectedRE.OnServerEvent:Connect(function(plr, style)
if not style or typeof(style) ~= "Instance" then return end -- we still want this here just in case
local ownedStyle = plr.OwnedStyles:FindFirstChild(style.Name)
if not ownedStyle then
print(plr.Name," is buying the ",style.Name," style.")
local price = style.Price.Value
local coins = plr.leaderstats.Coins
if price <= coins.Value then
coins.Value -= price
local newTool = style:Clone() do
newTool.Parent = plr.OwnedStyles
end
end
elseif ownedStyle then
print("test")
print(plr.Character.Head.NameTag.Title.TextColor3)
print(style.MainColor.Value)
if plr.Character.Head.NameTag.Title.TextColor3 ~= style.MainColor.Value then
print(plr.Name," equipped ",style.Name," tool.")
plr.Character.Head.NameTag.Title.TextColor3 = Color3.new(style.MainColor.Value)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = Color3.new(style.Secondary.Value)
plr.Character.Head.NameTag.PlayerName.TextColor3 = Color3.new(style.MainColor.Value)
plr.Character.Head.NameTag.PlayerName.TextStrokeColor3 = Color3.new(style.Secondary.Value)
elseif plr.Character.Head.NameTag.Title.TextColor3 == style.MainColor.Value then
print("triggered")
plr.Character.Head.NameTag.Title.TextColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Name.TextColor3 = Color3.fromRGB(255, 255, 255)
plr.Character.Head.NameTag.Name.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
end
end
end)
Instead of setting it to the rgb value of style.MainColor.Value, it just sets it to black. I added a print statement to try to debug it above the equip message:
print(style.MainColor.Value)
But the correct rgb numbers are showing but the color’s nametag is still black. What do I have to do?
use this function to convert your string example: “0, 1, 0” → Color3.new(0, 1, 0)
local function colorFromString(colorStr: string): Color3
local components = {}
for component in colorStr:gmatch("[^,]") do
table.insert(components, tonumber(component))
end
return Color3.new(table.unpack(components))
end
usage
local color = colorFromString(style.MainColor.Value)
or you can use Color3Values instead of StringValues
What would I have to change for Style.Maincolor.Value for this to work, and what do I need to change from the colorFromString function to fit my script?
local function colorFromString(colorStr: string): Color3
local components = {}
for component in colorStr:gmatch("[^,]") do
table.insert(components, tonumber(component))
end
return Color3.new(table.unpack(components))
end
StyleSelectedRE.OnServerEvent:Connect(function(plr, style)
if not style or typeof(style) ~= "Instance" then return end -- we still want this here just in case
local ownedStyle = plr.OwnedStyles:FindFirstChild(style.Name)
if not ownedStyle then
print(plr.Name," is buying the ",style.Name," style.")
local price = style.Price.Value
local coins = plr.leaderstats.Coins
if price <= coins.Value then
coins.Value -= price
local newTool = style:Clone() do
newTool.Parent = plr.OwnedStyles
end
end
elseif ownedStyle then
print("test")
print(plr.Character.Head.NameTag.Title.TextColor3)
print(style.MainColor.Value)
if plr.Character.Head.NameTag.Title.TextColor3 ~= colorFromString(style.MainColor.Value) then
print(plr.Name," equipped ",style.Name," tool.")
plr.Character.Head.NameTag.Title.TextColor3 = colorFromString(style.MainColor.Value)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = colorFromString(style.Secondary.Value)
plr.Character.Head.NameTag.PlayerName.TextColor3 = colorFromString(style.MainColor.Value)
plr.Character.Head.NameTag.PlayerName.TextStrokeColor3 = colorFromString(style.Secondary.Value)
elseif plr.Character.Head.NameTag.Title.TextColor3 == colorFromString(style.MainColor.Value) then
print("triggered")
plr.Character.Head.NameTag.Title.TextColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Name.TextColor3 = Color3.fromRGB(255, 255, 255)
plr.Character.Head.NameTag.Name.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
end
end
end)
local function colorFromString(colorStr: string): Color3
local components = {}
for component in colorStr:gmatch("[^,]") do
table.insert(components, tonumber(component))
end
return Color3.fromRGB(table.unpack(components))
end
StyleSelectedRE.OnServerEvent:Connect(function(plr, style)
if not style or typeof(style) ~= "Instance" then return end -- we still want this here just in case
local ownedStyle = plr.OwnedStyles:FindFirstChild(style.Name)
if not ownedStyle then
print(plr.Name," is buying the ",style.Name," style.")
local price = style.Price.Value
local coins = plr.leaderstats.Coins
if price <= coins.Value then
coins.Value -= price
local newTool = style:Clone() do
newTool.Parent = plr.OwnedStyles
end
end
elseif ownedStyle then
print("test")
print(plr.Character.Head.NameTag.Title.TextColor3)
print(style.MainColor.Value)
if plr.Character.Head.NameTag.Title.TextColor3 ~= colorFromString(style.MainColor.Value) then
print(plr.Name," equipped ",style.Name," tool.")
plr.Character.Head.NameTag.Title.TextColor3 = colorFromString(style.MainColor.Value)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = colorFromString(style.Secondary.Value)
plr.Character.Head.NameTag.PlayerName.TextColor3 = colorFromString(style.MainColor.Value)
plr.Character.Head.NameTag.PlayerName.TextStrokeColor3 = colorFromString(style.Secondary.Value)
elseif plr.Character.Head.NameTag.Title.TextColor3 == colorFromString(style.MainColor.Value) then
print("triggered")
plr.Character.Head.NameTag.Title.TextColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Name.TextColor3 = Color3.fromRGB(255, 255, 255)
plr.Character.Head.NameTag.Name.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
end
end
end)
Well then I messed somthing up try this to check the value look in the console for “Input: R, G, B Ouput: R, G, B” and send a screenshot or the printed message
local function colorFromString(colorStr: string): Color3
local components = {}
for component in colorStr:gmatch("[^,]") do
table.insert(components, tonumber(component))
end
return Color3.fromRGB(table.unpack(components))
end
StyleSelectedRE.OnServerEvent:Connect(function(plr, style)
if not style or typeof(style) ~= "Instance" then return end -- we still want this here just in case
local ownedStyle = plr.OwnedStyles:FindFirstChild(style.Name)
if not ownedStyle then
print(plr.Name," is buying the ",style.Name," style.")
local price = style.Price.Value
local coins = plr.leaderstats.Coins
if price <= coins.Value then
coins.Value -= price
local newTool = style:Clone() do
newTool.Parent = plr.OwnedStyles
end
end
elseif ownedStyle then
print("test")
print(plr.Character.Head.NameTag.Title.TextColor3)
print("Input:", style.MainColor.Value, "Output", colorFromString(style.MainColor.Value))
if plr.Character.Head.NameTag.Title.TextColor3 ~= colorFromString(style.MainColor.Value) then
print(plr.Name," equipped ",style.Name," tool.")
plr.Character.Head.NameTag.Title.TextColor3 = colorFromString(style.MainColor.Value)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = colorFromString(style.Secondary.Value)
plr.Character.Head.NameTag.PlayerName.TextColor3 = colorFromString(style.MainColor.Value)
plr.Character.Head.NameTag.PlayerName.TextStrokeColor3 = colorFromString(style.Secondary.Value)
elseif plr.Character.Head.NameTag.Title.TextColor3 == colorFromString(style.MainColor.Value) then
print("triggered")
plr.Character.Head.NameTag.Title.TextColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Title.TextStrokeColor3 = Color3.fromRGB(218, 218, 218)
plr.Character.Head.NameTag.Name.TextColor3 = Color3.fromRGB(255, 255, 255)
plr.Character.Head.NameTag.Name.TextStrokeColor3 = Color3.fromRGB(255, 255, 255)
end
end
end)
local function colorFromString(colorStr: string): Color3
local components = {}
for component in colorStr:gmatch("[^,]") do
table.insert(components, tonumber(component))
end
print("ColorFromString input:", colorStr, "output", table.unpack(components))
return Color3.fromRGB(table.unpack(components))
end
local function colorFromString(colorStr: string): Color3
local components = {}
for component in colorStr:gmatch("[^,]+") do
table.insert(components, tonumber(component))
end
print("ColorFromString input:", colorStr, "output", table.unpack(components))
return Color3.fromRGB(table.unpack(components))
end
You can remove the print function if it works but keep it for now just to debug