✓ 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
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()
end)
In our case we would write:
textButton.MouseButton1Click:Connect(function()
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
Is it supposed to print when the player clicks a button, or when they click anywhere?
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.