Finding who pressed the TextButton in surface GUI

so, I wanted to find out which player pressed a textbutton in a surfaceGUI but since its on a server script idk how…

You can use always use script.Parent.ClickDetector.MouseClick:Connect(plr)

The plr variable is the one that clicks or pressed the TextButton if you have a click detector for it

1 Like

but
image
look its a text button and that script is the one detecting it

You can have a RemoteEvent send Data to the Server, and print the Players name from there

can you elaborate?

[this is for 30_chars]

I have a server script that detects when the button is pressed and I want it to detect which player pressed that text button and the button is in a surface GUI in the workspace.

Not sure whats there to elaborate upon,

But I’ll keep it brief:

Create a RemoteEvent, and add the argument Player inside it:

RemoteEvent OnServerEvent:Connect(function(Player)
print(Player.Name.." Pressed the Button")
end)

And in your Button Script:

Button.Activated:Connect(function()
 RemoteEvent:FireServer()
end

my button is in the workspace, in a surfaceGUI and local scripts cant run in the workspace.

They can, and you will be mistaken to think that

  • Put the SurfaceGui inside StarterGui

  • Adornne (NOT PARENT) the UI to the Part

From there, you can use LocalScripts in the SurfaceGui


Plus, you can create a Regular Script, and set its RunContext property to Client, there you can use it in the workspace :slight_smile:

:open_mouth: u can do that? lemme see if it works

but I got a problem. here is my script

local currentID = 0

game.ReplicatedStorage.OrderItem.OnServerEvent:Connect(function(plr,customerName,items)
	for index, value in pairs(items) do 
		local cloned = script.SelectionFrame:Clone()
		cloned.Parent = script.Parent.ScrollingFrame
		cloned.Customer.Text = customerName
		cloned.TextLabel.Text = value.Name
		cloned.TextButton.MouseButton1Click:Connect(function(plr)
			print(plr)
			if plr:GetRankInGroup() >= 7 then
				cloned:Destroy()
				game.ReplicatedStorage.OrderItem:FireClient(plr,customerName,value)
			end
		end)
	end

end)

it clones a template into the scrolling frame which has a UI grid layout how can I make this still work?

can anyone help me? I can provide explorer if needed.

You can get the plr when it clicks the button like this

yourbutton.MouseButton1Up:Connect(function(plr)

end)

The plr variable finds the player who clicks the button. You may know the players name using print(plr.Name)

Edit: I forgot I replied to this already xd

1 Like