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

How can I get the players name printed on the output when clicked on a TextButton?

Hello there. I was making a button that opens another UI when a player clicks it. Then, I would have to reset my character because my code was...

game.StarterGui.ScreenGui..Enabled = true

How would I make the script print the players name?

Full Script

--Varibles
local gui = game.StarterGui
local plr = game.Players.LocalPlayer

--Function 

function open(plr)
	gui.NotifyGui.Enabled = true
	wait(.5)
end

script.Parent.MouseButton1Click:connect(open)

3 answers

✓ Accepted answer

Hi there! This is actually very simple, So first things first make sure you have the correct function going on! Now here's what the code should look like for the resolved issue!

local gui = game.StarterGui
local plr = game.Players.LocalPlayer

Gui.MouseButton1Click:connect(function(hit) -- Change Gui, connect it to your own Gui.

    gui.NotifyGui.Enabled = true
	print(hit.Parent) --This should print out the Players Name!
    wait(.5)

end)

4 comments

0

I have a error on "end)"

0

Ah sorry! I forgot to delete the end inside the code! The re-Edit should fix that now!

0

I'm getting "19:28:01.524 - Players.Player1.PlayerGui.ScreenGui.Button1.TextButton.LocalScript:7: attempt to index local 'hit' (a nil value)"

0

If that's the case try doing print(plr.Name)

plr is literally game.Players.LocalPlayer, so to access the name, add the below line

local name = plr.Name --Add after line 7, I'm guessing thats where you want it

2 comments

0

Main question is, how can I print it?

0

print(whatever) so in this case, print(plr.Name)

Hello. To print the name of the person who clicked you would do this. Hope it helped.


--Variables being used

local gui = game.StarterGui
local plr = game.Players.LocalPlayer
 
--Function you'd want to use
function open(hit)
    gui.NotifyGui.Enabled = true
    print(hit.Parent)
    wait(.5)
end
 
script.Parent.MouseButton1Click:connect(hit)

2 comments

0

Sorry, I'm getting "19:27:04.506 - Attempt to connect failed: Passed value is not a function"

0

"(event):connect(open)"

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