Mousebutton1click works on the server?

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?

appreciate any help

Plugins are a special case: Any script will run using the Plugin RunContext, regardless of whether it’s a LocalScript or server Script

1 Like

so it dosent matter if i use local scripts or serverscripts when making plugins appreciate it

1 Like

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.

1 Like

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 :slight_smile::+1:

1 Like

That’s what I’m thinking too, which is why I would do the connection on the server.

1 Like

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)

the player is given in the connection

cd.MouseButton1Click:Connect(function(player)

just try to stay away from using one script for each click detector

i meant for gui buttons sorry if i didnt clarify

and also it didnt return anything (nil)

to be exact, is mousebutton1click involved with the connections that you’d prefer using on the client or its other connections

1 Like

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

1 Like

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

1 Like

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,

appreciate @JohhnyLegoKing and @AMisspelledUsernaem for helping to clarify everything

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.