Checking for player who clicked a button

Hi i need help I need do If player click on button then I need something check BUT Click event work only on Script So I don’t know how to detect player who clicked

script.Parent.MouseButton1Click:Connect(function()
	local HttpService = game:GetService("HttpService")
	local s = "Censored WebHook"
	print("ok3")
	if game.Players.LocalPlayer:GetRankInGroup(5174745) >= 203 then
		print("ok")
		local Name = game.Players.LocalPlayer.Name
		local Data = {
		["username"] = "Training Information Bot",
		["content"] = "Training at 9:00AM has beed booked by"..Name
		}
		local DataDone = HttpService:JSONEncode(Data)
		script.Parent.Publish:InvokeServer(DataDone,s)
	end
end)
3 Likes

So the problem doesn’t seem to be in your LocalScript, rather the server-side script that listens when the Publish RemoteFunction gets invoked.

There’s another issue with your code currently though, which is the fact that if an exploiter in your game figures out the webhook since it’s exposed to the client, they could spam it very easily.

The script is pretty insecure,
so I’d suggest you to rewrite it to only fire to the server when the button gets clicked and then you do the rest on the server.

1 Like

What I would do is (and what is likely conventional):

  • Move the ScreenGui into the PlayerGui
  • Set the ‘Adornee’ of the ScreenGui to ‘Part’

This will show a unique GUI for each player/client where you are able to reference LocalPlayer. This will work in a LocalScript. This will mean that the Script will no longer work and you’d have to move the Publish event somewhere else, but it will be much neater.

1 Like

Or I do in server again if something and then do thing I want

Okay fixed one problem but another error

Is the Http Requests enabled?
Developer Hub has a detailed explanation on how you can enable Http Requests

Another reason why that error may have popped up would be that the link is invalid.

HttpRequest Is enabled so I don’t know

So I fixed this is problem but another error

1 Like

The problem there is that you’re JSONEncoding it twice, remove the DataDone and instead of sending DataDone, just send “data”.

So like this:

local HttpService = game:GetService("HttpService")
local Publish = script.Parent.Publish
Publish.OnServerInvoke = function(player, data, s)
    HttpService:PostAsync(s, data)
end

Done but this is another error code

The screenshot seems to be not loading for me, could you copy and paste the error here?

Sure here
21:34:27.911 - {“content”:“Training at 9:00AM has been booked by Pixeluted”,“username”:“Training Bot”}: Trust check failed

21:34:27.918 - Stack Begin

21:34:27.919 - Script ‘Players.Pixeluted.PlayerGui.GUI.Today.TextLabel.TextButton.LocalScript’, Line 13

21:34:27.920 - Stack End

The url is probably invalid, assuming you’re using discord webhooks, here’s a guide to creating a webhook. Then you should copy the URL and paste it in where ever you are storing the webhook link.

I created a valid webhook I not dumb

This is a gui right? and this is a localscript? Since it’s a localscript, you can write this:

local Players = game:GetService:("Players")
local Player = Players.LocalPlayer

Congratulations, now you have your player! Now, here:

["content"] = "Training at 9:00AM has beed booked by"..Name

Add this:

["content"] = "Training at 9:00AM has beed booked by "..Player.Name

i HoPe ThIs HeLpS ijnfwi :crazy_face:

I do but still error so I don’t know

Here
21:41:15.354 - {“content”:“Training at 9:00AM has been booked by Pixeluted”,“username”:“Training Bot”}: Trust check failed

21:41:15.355 - Stack Begin

21:41:15.356 - Script ‘Players.Pixeluted.PlayerGui.GUI.Today.TextLabel.TextButton.LocalScript’, Line 13

21:41:15.357 - Stack End

Maybe anything in the code is not accessible in a local script. You might try to change something to the Server-Sided script.

I doing InvokeServer(URL,Data)
So still don’t work
Still same error

You cannot run HTTP requests though a local script, you would have to create a remote that posts it through a server script.