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

How to get a players username when they click a surfaceGUI text button?

Asked by 3 years ago
Edited 3 years ago

Im trying to get the players username when they click a surfaceGUI textButton in a server script.

My code: ** FIXED MYSELF **

01local button = script.Parent
02local inUse = game.Workspace.Booth1:WaitForChild("InUse")
03local Owner = game.Workspace.Booth1:WaitForChild("Owner")
04 
05 
06 
07 
08button.MouseButton1Click:Connect(function()
09 
10    if inUse.Value == false then
11        inUse.Value = true
12        Owner.Value = ("Players username")
13 -- players username here ^^^^^^^^^^^
14 
15        print("Claimed!")
16    else
17        print("Already being used!")
18 
19        end
20end)

1 answer

Log in to vote
0
Answered by 3 years ago

I just fixed this myself. Instead of using a textbutton I used a ClickDetector inside the part and then put this script inside of it.

01local button = script.Parent
02local inUse = game.Workspace.Booth1:WaitForChild("InUse")
03local Owner = game.Workspace.Booth1:WaitForChild("Owner")
04 
05 
06 
07button.MouseClick:Connect(function(player)
08 
09    if inUse.Value == false then
10        inUse.Value = true
11        Owner.Value = (player.Name)
12        print(player.Name .. " pressed me!")
13 
14 
15        print("Claimed!")
16    else
17        print("Already being used!")
18 
19    end
20end)
Ad

Answer this question