Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I create an Account Age Nametag?

Asked by
BCGoss 0
6 years ago

I am trying to create a NameTag GUI that appears above a players head and says how old there account is for others to see. Could someone help me with that?

0
this isnt a request site AbstractDrawing 6 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The answer here is quite simple. Firstly, before I get into the scripting, you have to actually make your GUI. It's alright, i'll wait.

crickets

Oh, you're done? Fantastic! Let's learn how to actually make it work.

I've set up a script here which i'll explain in a minute:

local guiRaw = nil

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        local gui = guiRaw:Clone()
        gui.TextLabel.Text = plr.AccountAge.." days old"
        gui.Parent = char:WaitForChild("Head")
    end)

    plr:LoadCharacter()
end)

Let's explain what's happening here.

This script is subscribing to the "PlayerAdded" event provided by the Players class. This is fired whenever a player joins the game, which you probably should have known.

Then, once the "PlayerAdded" event is fired, we're then going to subscribe to another event: "CharacterAdded". Whenever this event is fired, we know the player has respawned, and therefore, have to give them the GUI.

Once the "CharacterAdded" event is fired, we're immediately going to clone the GUI you want to use. I've made a variable for this called guiRaw, which you can replace from 'nil' to wherever you put the GUI. Whether it be ServerStorage, workspace, whatever.

Now, once the GUI is cloned, we're then going to set the TextLabel's text inside of it to the player's account age. (If you changed the name of the TextLabel, you can either change its name to "TextLabel" or replace "TextLabel" in the script with the name)

Then, once we set the text, we're going to wait for the player's head to load, then set that player's head as the parent. It is optional to use :WaitForChild(), but I recommend it since sometimes the head could load a bit later, and the script would think of it as nil, thus resulting to an error.

After we subscribe to that event, I added plr:LoadCharacter(). This is because, sometimes, the player's character would be loaded before we actually subscribed to "CharacterAdded", so its good to load the character again, this time where we're already subscribed to "CharacterAdded".

This should answer your question, but if you want, you can also divide the number of days by 365 to get the number of years the player was on.

I hope this helped!

Ad

Answer this question