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

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

Asked by
TheePBHST 154
7 years ago

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

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

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)

0
I have a error on "end)" TheePBHST 154 — 7y
0
Ah sorry! I forgot to delete the end inside the code! The re-Edit should fix that now! OpticalAce 49 — 7y
0
I'm getting "19:28:01.524 - Players.Player1.PlayerGui.ScreenGui.Button1.TextButton.LocalScript:7: attempt to index local 'hit' (a nil value)" TheePBHST 154 — 7y
0
If that's the case try doing print(plr.Name) OpticalAce 49 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

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
0
Main question is, how can I print it? TheePBHST 154 — 7y
0
print(whatever) so in this case, print(plr.Name) dragonkeeper467 453 — 7y
Log in to vote
0
Answered by 7 years ago

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)
0
Sorry, I'm getting "19:27:04.506 - Attempt to connect failed: Passed value is not a function" TheePBHST 154 — 7y
0
"(event):connect(open)" Wilbob30 69 — 6y

Answer this question