This has probably happened before. You stick a SurfaceGui into workspace, use LocalPlayer in the script inside that SurfaceGui, and boom it doesn't work. You just want to figure out who clicked the button in the Gui, right? It's not that simple.
When dealing with ServerScripts you can't use LocalPlayer. Dealing with LocalScripts you can't use them in Workspace. And, the first argument of the
MouseButton1Click() event only provides numbers. You're probably thinking, "well, am I stuck now"?
What people don't often think of is how easy it is to overcome this problem. You can still use a LocalScript, and you just need to move the SurfaceGui to StarterGui.
There is a property many people don't use called
Adornee. Adornee is basically a property that says "hey put me on this object even though I am somewhere else".
You can either set the property manually by clicking on it and directing it to the part. Or you can add it to the top of the script you have. Here is an example.
script.Parent.Adornee = game.Workspace.Part local player = game:GetService('Players').LocalPlayer script.Parent.Button.MouseButton1Click:connect(function() print(player.Name) --Granted this would be printed in the local logs. This is just an example. end)