I am currently programming a nametag script that loops through each that letter and tweens it according to what effect a player has equipped.
Here’s my code thus far:
function PlayerAdded(Player)
local NametagStyle = "Wave"
local function CharacterAdded(Character)
local Nametag = script.Nametag:Clone()
local Count = 1
for Letter in string.gmatch(Player.Name, "(%w)") do
local TextLabel = Instance.new("TextLabel", Nametag.Letters)
TextLabel.Size = UDim2.new(.05, 0, .75, 0)
TextLabel.Position = UDim2.new(Count*0.05, 0, 0, 0)
TextLabel.Text = Letter
TextLabel.BackgroundTransparency = 1
TextLabel.Font = Enum.Font.GothamBold
TextLabel.TextColor3 = Color3.new(1, 1, 1)
TextLabel.TextSize = 25
Count += 1
end
Nametag.Parent = Character.PrimaryPart
while Character do
wait(5)
NametagFunctions[NametagStyle](GetLabels(Nametag.Letters))
end
end
CharacterAdded(Player.Character or Player.CharacterAdded:Wait())
Player.CharacterAdded:Connect(CharacterAdded)
end
Now, this works perfectly fine. However, I am not sure how I can center the textlabels initially? When I press play here, you can see that the TextLabels are aligned to the left (as expected).
How can I modify code to make the TextLabels align to the center?
function PlayerAdded(Player)
local NametagStyle = "Wave"
local function CharacterAdded(Character)
local Nametag = script.Nametag:Clone()
Nametag.Size = UDim2.fromScale(#Player.Name/2.5, 1.5)
local Labels = {}
local Count = 1
for Letter in string.gmatch(Player.Name, "(%w)") do
local TextLabel = Instance.new("TextLabel", Nametag.Letters)
TextLabel.Size = UDim2.new(.05, 0, .75, 0)
table.insert(Labels, Count, TextLabel)
TextLabel.AnchorPoint = Vector2.new(.5,0)
TextLabel.Text = Letter
TextLabel.Name = Letters[Count]
TextLabel.BackgroundTransparency = 1
TextLabel.Font = Enum.Font.GothamBold
TextLabel.TextColor3 = Color3.new(1, 1, 1)
TextLabel.TextScaled = true
Count += 1
end
Nametag.Parent = Character.PrimaryPart
local function Center()
for I, Label in pairs(Labels) do
Label.Size = UDim2.fromScale(1/#Labels, 1)
Label.Position = UDim2.fromScale(I/#Labels - (Label.Size.X.Scale/2), 0)
end
end
Center()
while Character do
wait(5)
NametagFunctions[NametagStyle](Labels)
end
end
CharacterAdded(Player.Character or Player.CharacterAdded:Wait())
Player.CharacterAdded:Connect(CharacterAdded)
end