so everytime i want to detect if a player clicked a button on the server i fire a remote event/function
but to my surprise turns out that if i put a server script with the run context of “Server” it detects that the player clicked the button so i dont need to fire any remote events
im just surprised that no one have ever brought this up, and maybe its because of security reasons?
if anyone help to clear up the confusion, because if theres no issue then i would personally consider this as revolutionary lol.
and also the way i discovered this is i was working on a plugin and i wanted to detect button clicks but sending remote events or using local scripts in plugins i dont think thats good practice (but i might be wrong though)
so if it wasnt secure in game will be it ok to use it in plugins that involve guis?
It really shouldn’t be a security question but rather a performance question. I’ve seen people say that it can cause performance issues, but I don’t really know if thats the case. I would say go ahead ad do the connection on the server, just make sure to do sanity checks.
wouldnt it be more performance intensive if you fire a remote event every time the player clicks, because suppose if the player spams, it would be better to straight away detect rather than send every time via a remotefunction/removeevent at the end of the day they are both rbx script connections
Pretty much, although from my experience, functions/methods/events that deal with user input still prefer being used within a LocalScript rather than a server Script, even though their RunContext is the same when they’re being used in plugins
@TypicalCEO I edited my reply to clarify and add more information
so regarding security, what may be an issue is how to get the player who clicked the button,
because if you assign a main player it could be that an another player can somehow access that button and then click it, causing the server to think that the main player clicked it when in reality its the exploiter,
so the issue is how to get the player who clicked the button
currently the method im using is to just do
script.Parent.Parent.Parent
until i reach the startergui’s parent (which would be the player)
oh for gui buttons you could get the player in multiple ways
button:FindFirstAncestorOfClass("Player")
or if the script is not in the gui then get the player when you’re indexing the gui. In most cases you’re going to only want to use one script and index the gui
MouseButton1Click is able to run even when used in a regular server script that’s inside of a GUI, so that would explain why it’s also working when used in a plugin
appreciate you all for the clarification, and just for conclusion
using the mousebutton1click on the server side does not impose any issue regarding security or performance,
in some cases its better to use remote functions/ remove events and sometimes its better using serverscripts straight away,
plugins use a runcontext that has nothing to do with the server or the client, so using localscripts or using serverscripts do not have that large of a difference,