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
GiveNameTitle script, located in ServerScriptService.
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)
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!
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
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
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
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)
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
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”