I am currently working on a combat game, and I’ve come across an issue. I want the player to be able to do only one attack at a time, so I created a variable that is turned off or on whether or not the player is in the middle of an attack. I then checked this before the player could make another attack.
I want to be able to communicate this busy value across multiple scripts. What would be the best way to go about that?
So far I’ve thought of making a boolValue in replicated storage and checking it whenever nessecary, but I want to know if any better options are available.
Regarding Communication with Local Scripts, a Bindable event works
But I think a Module Script storing the previously mentioned Variable inside the Module would work just fine.
There are several ways to communicate between two local or two server scripts. The way I find the most useful is using principles found in Event Driven Architecture.
Ideally, you can set up a subscription to a property and publish an event to that subscription once the state is updated.
Another approach is to use a channel which can trigger an update event once you invoke the channel. This channel can be used by both local scripts.
And finally, we can use async bindable events, this involves using bindable events which can be found in the ROBLOX API.
For server → server and client → client communication you can use BindableEvents:
--LocalScript 1
local signal = Instance.new("BindableEvent")
signal.Name = "Signal"
signal.Parent = script
task.wait(5) --wait for 5 seconds, so the other local script loads
signal:Fire("Hello", 5, true) --send some data
--LocalScript 2
local signal = script1:WaitForChild("Signal")
signal.Event:Connect(function(...)
print(...) --Hello, 5, true
end)