I am working on a game and I don't need help with any script specifically but I was hoping to get help on an issue I have encountered. I have a script that runs to close certain parts of the map, and has a lot of waits and random sequences. This works fine when I run it, but I want there to be the option for someone to win the game (by being the last one alive) even if the zone isn't fully finished running yet. I also need the zone to start at a point in the main script that will have the player win. I don't have the winner code written yet because I don't know how to incorporate it with the rest of the loop. I hope this is specific enough I know I put quite a bit into this but maybe someone can help :).
BindableEvents.
Let's say we have Script A
and Script B
, both loaded in completely different places in the gamespace.
First, we'll put a BindableEvent in ReplicatedStorage. This is how the two scripts will interact.
!ReplicatedStorage -> Events -> GiveANumber
Script A
looks like this:
while wait(1) do game:GetService("ReplicatedStorage").Events.GiveANumber:Fire(math.random(1,5)) end
and Script B
looks like this:
game:GetService("ReplicatedStorage").Events.GiveANumber.Event:Connect(function(arg) print("Wow, Script A just gave me a "..arg.."! Thanks, Script A!") end)
If we run this, Script A
will send a random number between 1 and 5 to the BindableEvent, which will deliver the number to Script B
which will output it.
EDIT: If you want to communicate between the server and client or vice-versa, use RemoteEvent
s. BindableEvents will not work in this situation.