Roleplay's TextColor3 won't change

I’ve finished a roleplay name changer and it works just fine. But what i want to achieve now is so player can change the color of their RP name from a list of colors (aka buttons) i’ve created.
I tried to do it on my own but it’s really hard to, since the nameGui is an instance created in a script.

Anyway here are the details about my problem

Here is the list i did and as u can see each color is a button. So i dont have to change all the buttons names , im trying to put the script into each button so the RP text color would change to the button’s color
image

GiveNameTitle script, located in ServerScriptService.

game.Players.PlayerAdded:Connect(function(plr)
	
	
	plr.CharacterAdded:Connect(function(char)
		
		
		local nameGui = Instance.new("BillboardGui")
	
		nameGui.StudsOffset = Vector3.new(0, 2, 0)
		
		nameGui.Size = UDim2.new(0, 200, 0, 50)
		
		nameGui.Name = "NameGui"
		nameGui.Parent = char.Head
		
		
		local nameLabel = Instance.new("TextLabel")
		
		nameLabel.Text = plr.Name
		
		nameLabel.TextScaled = true
		
		nameLabel.Size = UDim2.new(0, 200, 0, 50)
		
		nameLabel.BackgroundTransparency = 1
		
		nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
		
		nameLabel.Name = "NameLabel"
		nameLabel.Parent = nameGui
	end)
end)

GiveNameTitle is based on ChangeNameScript, located in ServerScriptService.

local remoteEvent = game.ReplicatedStorage.NameChangeEvent


remoteEvent.OnServerEvent:Connect(function(plr, name)
	
	
	local char = plr.Character or plr.CharacterAdded:Wait()
	
	
	local filteredName = game:GetService("TextService"):FilterStringAsync(name, plr.UserId) 
	
	local filteredNameAsString = filteredName:GetNonChatStringForBroadcastAsync() 
	

	local nameGui = char.Head:FindFirstChild("NameGui")
	
	local nameLabel = nameGui:FindFirstChild("NameLabel")
	
	
	nameLabel.Text = filteredNameAsString	
end)

The placement of everything.

Thank you so much for helping <3

You can loop through all the buttons, when a button is pressed, fire a remote event to the server (which would send arguments of player & color) . Allow this event to access the player’s character nametag using given arguments and change the color!

You can do something like this:

Server script:

local RolePlayNameEvent = game.ReplicatedStorage.NameChangeEvent

RolePlayNameEvent.OnServerEvent:Connect(function(Player, Name, TextColor)
	local Character = Player.Character
	local FilteredName = game:GetService("TextService"):FilterStringAsync(Name, Player.UserId) 
	local FilteredNameAsString = FilteredName:GetNonChatStringForBroadcastAsync() 
	
	local NameGui = Character.Head:FindFirstChild("NameGui")
	local NameLabel = NameGui:FindFirstChild("NameLabel")
	
	NameLabel.TextColor3 = TextColor
	NameLabel.Text = FilteredNameAsString
end)

And a local script:

local RolePlayNameEvent = game.ReplicatedStorage:WaitForChild("NameChangeEvent")
local ButtonFrame = script.Parent.ButtonFrame -- change this to the frame where the buttons are stored


for _, v in pairs(ButtonFrame:GetChildren()) do
    v.MouseButton1Click:connect(function()
        local Text = "Name"
        local Color = v.BackgroundColor3
        RolePlayNameEvent:FireServer(Text,Color)
    end)
end

Yep, I was about to respond with something very similar to this

However, your while wait() do is completely unnecessary, and the code will work perfectly without it!

1 Like

I assume that the local script needs to be placed in the frame where all the buttons are.
It works now, the color is changing but now the input of roleplay name isn’t working
https://gyazo.com/53e73c1b7645060ebe3fda8d0e0094bf

You have to change to change the "local Text = “Name” to “local Text = TextBox.Text”.

I did and it says that TextBox is unknown

local RolePlayNameEvent = game.ReplicatedStorage:WaitForChild("NameChangeEvent")
local ButtonFrame = script.Parent -- change this to the frame where the buttons are stored


for _, v in pairs(ButtonFrame:GetChildren()) do
    v.MouseButton1Click:connect(function()
        local Text = TextBox.Text
        local Color = v.BackgroundColor3
        RolePlayNameEvent:FireServer(Text,Color)
    end)
end

or do i have to change the local ButtonFrame in where the text box is located?

The error must be somewhere else. The name is still not changing but now if i change the color, my username will change into Instance. I keep looking and i cannot see where the problem is.
https://gyazo.com/8927d7582fc657843af8aa8528c79d49

Changing the RP name is still not working and now if i try to change the color it will basically be invisible as shown below
https://gyazo.com/555aebe99347f447dcd46e5157e80303

I’m starting to think that theres something wrong in this script but im not sure since im not a good scripter and i’m sorry for that.

local confirm = script.Parent.ConfirmButton

local input = script.Parent


local remoteEvent = game.ReplicatedStorage.NameChangeEvent



confirm.MouseButton1Click:Connect(function()
	
	
	local name = input.Text
	
	
	input.Text = ""
	
	
	if string.len(name) < 1 or string.len(name) > 50 then return end
	
	
	remoteEvent:FireServer(name)
end)

input.Text = " "

And as you requested…

local RolePlayNameEvent = game.ReplicatedStorage:WaitForChild("NameChangeEvent")
local ButtonFrame = script.Parent.RPColor -- change this to the frame where the buttons are stored


for _, v in pairs(ButtonFrame:GetChildren()) do
    v.MouseButton1Click:connect(function()
        local Text = script.Parent.RolePlayName.Text -- This sets the player name to be the current text of the RolePlayName TextBox
        local Color = v.BackgroundColor3
        RolePlayNameEvent:FireServer(Text,Color)
    end)
end
1 Like

It works if i dont press the Change Name button
https://gyazo.com/744d168641dd045c31c3671cfc5cfd60

But anyway thank you so much for helping and for ur patience over me. <3

You’d need to save the name in a variable outside the functions in order for it to change even after the text box is cleared. Just make sure the variable is changed when they click the “Change Name” button.

@ii_G0N3
Pretty sure it’s not changing the name when your using the Change Name button because your setting TextColor first, however TextColor is nil since you only passed the name from the client. Setting a Color3 value to nil would error and break the code.

In your OnServerEvent try changing “NameLabel.TextColor3 = TextColor” to “NameLabel.TextColor3 = TextColor or NameLabel.TextColor3”