Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get these two scripts to communicate? Tool Script + Gui Script

Asked by 3 years ago

I have a joystick gui I made and a tool script that I want to communicate with. I did not create the gun but found it at Roblox. The joystick controls which way the character is facing, how can I make the gun only shoot when your finger is on the joystick and not the rest of the screen? I think I need a RemoteEvent in ReplicatedStorage but I'm not quite sure. Both scripts are client side atleast that's what Studio Output tells me. If you look I have a tool (handgun) inside of StarterPack which has a script (HandgunScript) and I have a screenGui within StarterGui containing my joystickScript. Any help is appreciated. All links are down below, Thank you everyone! [EDIT: my scripts where to long for scripting helpers, so everything has to be a link -.- Sorry]

LINKS:

joystickScript

https://pastebin.com/d9Zf71gP

HandgunScript (I do not take credit)

https://pastebin.com/3BJpkAUD

Explorer

https://imgur.com/a/ML92FHU

Handgun

https://www.roblox.com/library/1533692920/Working-Pistol-Gun-WORKING?ViewInBrowser=true&CreatorId=411120421&SearchId=77AE0DB5-876D-4D26-BFEA-968F8C0F423A&Category=Model&Position=1&SearchKeyword=gun&CreatorType=User&SortType=Relevance

Thank you to everyone who takes the time to look at this and any help is greatly appreciated, even a wikilink or even just a rough idea. Looking forward to your answers/suggestions!

0
Make sure that the GUI script is local and the tool is server! then your able to use remote events to communicate with the other script, Make sure the remote event is in the ReplicatedStorage! Finty_james 269 — 3y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
3 years ago
Edited 3 years ago

So Remote Events are how the server and client communicate, but Bindable Events are how client scripts and server scripts communicate with each other on only the client or only the server.

So for server scripts, I'd recommend you just keep the bindable event objects in server storage, and for client scripts, I would keep them in replicated storage.

To receive and do stuff with the data:

local BE = game.ReplicatedStorage.BindableEvent

BE.Event:Connect(function(stuff)
    print(stuff)
end)

And to send data:

local BE = game.ReplicatedStorage.BindableEvent
BE:Fire("Hello World!")

And those running on two different scripts would cause the first script to print "Hello World!" to the output.

Edit: Also noticed you only knew they were client scripts because the output said so, but if you look at the actual scripts in the explorer, client scripts will visibly have a different icon than server scripts.

Ad

Answer this question