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.