Local Script To Local Script Communication

I want to communicate from one local script to another local script. Kinda similar to how bindable events work. I know this is a security issue because there are so many ways to abuse it. But I was wondering if you could communicate to another local script that’s under the same client (Same PlayerGui, Character, ReplicatedStorage, etc).

I’ve tried re-creating this is 2 ways.

Bool Values

I tried re-creating it with bool values. One script can set the value to true, then the other script waits for the value to change to true. Once it does, it sets it back to false and runs a function.

Now the problem with this is that sometimes its not perfect, but there are ways to send data with this such as string values, and other object values in its child, but it’s not very effective/efficient. And there are some type’s that you cant pass over (enums, functions, tables (I guess with tables you can JSONEncode), etc).

Module Scripts

Now module scripts make it way easier and you can send any type of data. But there are cons. The biggest con I would think of is it doesn’t run on its own. You need to require it for it to run. And it also runs every time you require it. That becomes a problem when you require it multiple times and you only need it to run once.

Another problem with Module Scripts is that you cant require other module scripts that require the current module scripts; it goes in an infinite loop.

If anyone has any solutions, ideas feel free to comment them below. I would love to read every one of them. If there is no way, I would like @Roblox to add it, but keep in mind they might not because of how big of a security threat this could be. But again, you can make it so the events only fire if they’re coming from the same client.

Thanks for reading, Cya.

- UndefinedN00B & xXCodeAltXx

6 Likes

BindableInstances you should use for communication between 2 of the same classes

3 Likes

Well, you could try using a script as a means of communication between both the localscripts. You could fire a remote event from “LocalScript1” to “Script”, that then finds the player that “LocalScript1” tells it to, then fires a remote event from “Script” to “LocalScript2”. A pretty roundabout way, but it would work.

1 Like

BindableInstances? I’ve never heard of that. Could you explain what that could be?

Hey, I’ve also tried that but its not very efficient. But it also brings up another problem, client-sided objects do show up in the server which means iirc when the server passes it back to the client, they appear nil. I might be wrong here, but i will try it again to see if it works. Thanks for the reply!

Yeah, it is pretty inneficient - but for a last case scenario it’s not too bad.

Yes I believe that is true. I had that problem with server-to-client communication the other day. However, objects such as intValues, boolValues, and that sorta thing you could pass the value of them over to the server, not the actual object. And I believe you could replicate the object over to the server as well, though I haven’t tried it myself.

Odd, I thought that Bindable Events/Functions work client-to-client as well. I’ve been looking around the internet about that, and it seems scattered, with some people saying it is, and some people saying it isn’t. I’d test it out yourself with something simple, like passing a number over or something. Unfortunately I’m not on my computer where Roblox Studio is so I can’t test this myself.

12 Likes

You’re right! You can use Bindable Events Client-to-Client! In the wiki, it says for a Server Script to communicate to another Server Script! I didn’t know you can Communicate with local scripts! Thanks so much!

6 Likes

If the two local scripts are both on the same client then they can communicate the same way server scripts can communicate with other server scripts using bindable events and functions, module scripts, or the global table (but module scripts should be used instead of that).

If you’re talking about two local scripts on different clients then you would have to use remote events or functions to go Client1 → Server → Client2

5 Likes

Maybe you can use values and a repeat wait() until to allow the scripts to communicate with each other.

Also can you help me when your done with him?

A polling method (repeat wait() until...) can often be replaced with an event-based method (SomeValue.Changed:Wait()) and is usually less “messy” in my opinion.

Oh I didnt know there is such a thing. Ok I will use that in my scripts now!

Help with the post you linked to? I’ll see what I can help with.

Ok thanks so much!
I am looking forward to the help!

Hey, my pleasure! It confirmed it for myself to - we’re all learning :laughing:

Have a good week/weekend!

2 Likes

BindableInstances are just BindableEvents and BindableFunctions

1 Like