Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Account age button is doing nothing, someone help?

I am making a simple game that shows you your account age when you put in your username, something to practice some scripting. I put this script into the button that you press after putting in your username,

game.Players.PlayerAdded:Connect(function(plr)
	if plr.MouseButton1Click then
		print(plr.AccountAge)
	end
end)

I am a beginner in Lua, so I just tried making a script based off some stuff I saw on the developer hub. Can anyone help me out as to what path to go? Kinda just whipped up some code here.

2 comments

0

Is it supposed to print when the player clicks a button, or when they click anywhere?

0

Hey, thanks for replying. I made a GUI and it has a text button and a text box. The user puts in their username, and then presses ''Get Account Age'', which should give them their account age, but I can't find a tutorial or roblox dev hub post that explained what to do.

1 answer

✓ Accepted answer

First of all, we need to get the GUI button. Make sure your script is a LocalScript and put it inside of a GuiButton. For instance, the structure could look like this inside of StarterGui: ScreenGui > Frame > TextButton > LocalScript

Now to get this TextButton in the script:

local textButton = script.Parent -- The TextButton is the "Parent" of the script because it is above the script in the game hierarchy 

Now, since we're in a LocalScript, this script will be replicated to each individual player in the game. To understand this more I strongly recommend you read this. That being said, we can get the player like so:

local player = game.Players.LocalPlayer

Also, MouseButton1Click is not a player event, but a GuiButton event. To handle events, the syntax is as follows (where Instance would be something like Player or GuiButton):

Instance.Event:Connect(function()
	-- do what you want here
end)

In our case we would write:

textButton.MouseButton1Click:Connect(function()
	-- do what you want here
end)

Bringing everything together we get:

local player = game.Players.LocalPlayer
local textButton = script.Parent

textButton.MouseButton1Click:Connect(function()
	print(player.AccountAge)
end)

Hope this helped, and good luck!

2 comments

0

Thank you so much, this worked.

0

No problem. Please click "Accept Answer," so other people know this has been solved

This discussion is preserved as it was. New answers, comments, and votes are closed.