I have been trying to make a surface GUI that shows how long someone has been working and how much they have earned (As well as giving them money.) However I can't figure out how to find the player who clicked the button. Right now I have it firing an event but that would still give everyone on the server money. Any tips?
Server Script:
------------------Declerations------------------
TPH = script.Parent.Frame.PH1 -- Time place holder
MPH = script.Parent.Frame.PH2 -- Money place holder
Btn = script.Parent.Frame.Button
O = false --True or false for onClicked
Timer = script:WaitForChild("Timer") --Base number for stopwatch
BT = script.Base_Money
MPS = script.Money_Per_Second
------------------------------------------------
---Creation and nameing of User pinging event---
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClientPing = Instance.new("RemoteEvent", ReplicatedStorage)
ClientPing.Name = "ClientPing"
------------------------------------------------
------------------Main Script-------------------
function onClicked()
print("clicked")
if O == true then
ClientPing:FireAllClients(O)
print("Ping sent")
Btn.BackgroundColor3 = Color3.fromRGB(97,255,107)
Btn.Text = "Start"
O = false
wait(3)
BT.Value = 0
Timer.Value = 0
Timeset()
Moneyset()
else
ClientPing:FireAllClients(O)
print("Ping sent")
Btn.BackgroundColor3 = Color3.fromRGB(255,0,0)
Btn.Text = "End"
O = true
end
print(O)
while O do
wait(1)
print(O)
BT.Value = BT.Value + MPS.Value
Timer.Value = Timer.Value + 1
Timeset()
Moneyset()
end
end
------------------------------------------------
function Timeset()
local formatString = "%i:%.2i"
local seconds = math.floor(Timer.Value % 60)
local minutes = math.floor(Timer.Value / 60)
local output = formatString:format(minutes, seconds)
TPH.Text = output
end
------------------------------------------------
function Moneyset()
MPH.Text = BT.Value
end
Btn.MouseButton1Down:Connect(onClicked)
Local Script: The local script is not done but it would give the player money while O == true.
Plr = game.Players.LocalPlayer
wait(1)
print("run1")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClientPing = ReplicatedStorage:WaitForChild("ClientPing")
function ClientPing(O)
print(O "ClientPinged")
end
ClientPing.OnClientEvent:Connect(ClientPing)
P.S. I am new to scripting so I am going for function over beauty but any corrections would be very much welcomed.

6 comments
You shouldn't handle GUI related objects on the server side Script. The server can't see the PlayerGui and a SurfaceGui must be under it for it to know which player is interacting with it. Additionally, what your local script is doing should be done in a server Script.
What do you mean by it has to go under the player GUI? If it is under player GUI wouldn't the surface GUI not know were to display its self?
Also thanks for the correction on the local script I must have overlooked that in my hast.
You use the Adornee property to set it's part to be displayed on. See it's documentation on RobloxDev. This way makes it easier for you to handle input and replicate changes specifically to one player.
I think there is a :PlayerWhoClicked or something? I don't know if that is the name, but I have used it or something like it. (and the surface GUI is in a part with a click detector right?)
No it is just a button