So when you use Admin systems like Adonis or HD admin. They always this feature which allows the Moderator player to make a nametag to anyone they like by chatting in chat with *:name (player name) (anything they want).
I’m trying to figure out, how to do this (with the same font etc) with a GUI button which when clicked changes the person who click the GUI to a nametag named Red Team. If possible, I would like this to be changeable back into anything by the moderator (group rank ID) just the chat.
Change Character.Humanoid.DisplayName to whatever you want to achieve this. You will not be able to see your own name as this is completely normal for roblox as you can see at the start of your GIF you were not able to see your own name:
To achieve seeing your own name you should make a Model with a Part called “Head” and a Humanoid iside of it. You would name the model to whatever you want the nickname to be or change the .DisplayName property of the Humanoid as shown above.
local function getPlayer(name)
for i, v in pairs(game.Players:GetChildren()) do
if string.lower(name) == string.lower(string.sub(v.Name, 1, #name)) then
return v
break
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
player.Chatted:Connect(function(msg)
if msg:sub(1, 6) == ':name ' then
local plr = string.sub(msg:sub(7))[1]
local newName = string.sub(msg:sub(7))[2]
if getPlayer(plr) then
getPlayer(plr).Character.Humanoid.DisplayName = game:GetService('TextService'):FilterStringAsync(newName)
end
end
end)
end)
end)
The code you would need to use to name the player.
local function name(character, nickname)
if workspace:FindFirstChild(character.Name .. "'s nickname") then -- if there is already a nickname for the player
local model = workspace[character.Name .. "'s nickname"] -- get the model
model.Humanoid.DisplayName = nickname -- change the name
else
local model = Instance.new("Model")
model.Name = character.Name .. "'s nickname" -- Important so we can retreive it later
local head = Instance.new("Part")
head.Name = "Head" -- Has to be called Head else it won't work
head.CanCollide = false -- So you can't touch it
head.Size = Vector3.new()*1.5 -- So the head is about the side of a roblox head, we can't make it the exact size because of hitboxes.
head.Transparency = 1 -- This is so you can't see it
local humanoid = Instance.new("Humanoid")
humanoid.DisplayName = nickname
humanoid.BreakJointsOnDeath = false -- so the weld does not get destroyed
humanoid.RequiresNeck = false
humanoid.MaxHealth = 0
humanoid.Health = 0 -- Just to be sure this is set to 0 as well
local weld = Instance.new("ManualWeld") -- So the name sticks with the player
weld.Part0 = head
weld.Part1 = character.Head
-- Parent it all together to make it visible
weld.Parent = weld.Part0
head.Parent = model
humanoid.Parent = model
model.Parent = workspace
end
end
You can use the code above with @GoteeSign’s code to create this effect:
You’d basically call the function that KJry_s stated everytime when the player clicks the button in a default script.
local Players = game:GetService('Players')
local button = script.Parent
local player = button:FindFirstAncestorWhichIsA('Player')
local newName = 'Red Team'
local function name(character)
if workspace:FindFirstChild(character.Name .. "'s nickname") then -- if there is already a nickname for the player
local model = workspace[character.Name .. "'s nickname"] -- get the model
model.Humanoid.DisplayName = newName -- change the name
else
local model = Instance.new("Model")
model.Name = character.Name .. "'s nickname" -- Important so we can retreive it later
local head = Instance.new("Part")
head.Name = "Head" -- Has to be called Head else it won't work
head.CanCollide = false -- So you can't touch it
head.Size = Vector3.new()*1.5 -- So the head is about the side of a roblox head, we can't make it the exact size because of hitboxes.
head.Transparency = 1 -- This is so you can't see it
local humanoid = Instance.new("Humanoid")
humanoid.DisplayName = newName
humanoid.BreakJointsOnDeath = false -- so the weld does not get destroyed
humanoid.RequiresNeck = false
humanoid.MaxHealth = 0
humanoid.Health = 0 -- Just to be sure this is set to 0 as well
local weld = Instance.new("ManualWeld") -- So the name sticks with the player
weld.Part0 = head
weld.Part1 = character.Head
-- Parent it all together to make it visible
weld.Parent = weld.Part0
head.Parent = model
humanoid.Parent = model
model.Parent = workspace
end
end
button.MouseButton1Click:Connect(function()
name(player.Character)
end)
I put a print function after the name(player.Character) on the last line before end) to see if it was my fault localising the button, which looks like it working but the function it self isn’t.
It does make a model in workspace with players name and nickname but isn’t exa
I looked into script output and no error is showing up.
The changes are only being made to the client, that’s the thing
Here’s what I think you can do:
Create a RemoteEvent inside ReplicatedStorage
Set this as your LocalScript for detecting the button when activated:
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Button = script.Parent
local NameChange = "Red Team"
local function Clicked()
print("Clicked")
Event:FireServer(NameChange)
end
Button.MouseButton1Down:Connect(Clicked)
Handle the name changes on the server instead of on the client:
--Server Script inside ServerScriptService
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Event.OnServerEvent:Connect(function(Player, NameChange)
print("Event fired")
print("Name: ", NameChange)
local Char = Player.Character
if Char then
Char.Humanoid.DisplayName = NameChange
end
end)
RemoteEvent ------- Replicated Storage
LocalScript ------ Inside the RemoteEvent
Put the first code of line to that Local script.
Make the Serverscript that inside the ServerScriptService with that code you put in.
I mean you can either do it that way or @flkfv’s way, although I do remember some issues with keeping regular ServerScripts inside descendants of GUI Objects
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local button = script.Parent
local player = button:FindFirstAncestorWhichIsA('Player')
Event.OnServerEvent:Connect(function(Player, NameChange)
print("Event fired")
print("Name: ", NameChange)
local Char = Player.Character
if Char then
Char.Humanoid.DisplayName = NameChange
end
end)
In the second local script, I got :
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Button = script.Parent
local NameChange = "Red Team"
local function Clicked()
print("Clicked")
Event:FireServer(NameChange)
end
Button.MouseButton1Down:Connect(Clicked)
In the third local script I got :
local Players = game:GetService('Players')
local button = script.Parent
local player = button:FindFirstAncestorWhichIsA('Player')
local newName = 'Red Team'
local function name(character)
if workspace:FindFirstChild(character.Name .. "'s nickname") then -- if there is already a nickname for the player
local model = workspace[character.Name .. "'s nickname"] -- get the model
model.Humanoid.DisplayName = newName -- change the name
else
local model = Instance.new("Model")
model.Name = character.Name .. "'s nickname" -- Important so we can retreive it later
local head = Instance.new("Part")
head.Name = "Head" -- Has to be called Head else it won't work
head.CanCollide = false -- So you can't touch it
head.Size = Vector3.new()*1.5 -- So the head is about the side of a roblox head, we can't make it the exact size because of hitboxes.
head.Transparency = 1 -- This is so you can't see it
local humanoid = Instance.new("Humanoid")
humanoid.DisplayName = newName
humanoid.BreakJointsOnDeath = false -- so the weld does not get destroyed
humanoid.RequiresNeck = false
humanoid.MaxHealth = 0
humanoid.Health = 0 -- Just to be sure this is set to 0 as well
local weld = Instance.new("ManualWeld") -- So the name sticks with the player
weld.Part0 = head
weld.Part1 = character.Head
-- Parent it all together to make it visible
weld.Parent = weld.Part0
head.Parent = model
humanoid.Parent = model
model.Parent = workspace
end
end
button.MouseButton1Click:Connect(function()
name(player.Character)
end)