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

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

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

My code: ** FIXED MYSELF **


local button = script.Parent
local inUse = game.Workspace.Booth1:WaitForChild("InUse")
local Owner = game.Workspace.Booth1:WaitForChild("Owner")




button.MouseButton1Click:Connect(function()
	
	if inUse.Value == false then
		inUse.Value = true
		Owner.Value = ("Players username")
 -- players username here ^^^^^^^^^^^
		
		print("Claimed!")
	else
		print("Already being used!")
		
		end
end)

1 answer

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.

local button = script.Parent
local inUse = game.Workspace.Booth1:WaitForChild("InUse")
local Owner = game.Workspace.Booth1:WaitForChild("Owner")



button.MouseClick:Connect(function(player)

	if inUse.Value == false then
		inUse.Value = true
		Owner.Value = (player.Name)
		print(player.Name .. " pressed me!")


		print("Claimed!")
	else
		print("Already being used!")

	end
end)

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