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

How exactly does using the same script multiple times work?

Asked by 4 years ago

This isn't a question about a particular script but about how the scripts themselves run.

Example: I have an attack in game that is triggered through a key. I have it put where everyone can access it. Multiple players are using said script to fire off the attack.

Would a new "instance" of the script be run every single time the script is called upon. Or is there a chance for issues to ever arise where say, Player1 and Player2 are aiming in two separate places, both call the script for the attack, but Player2's attack instead aims where Player1 was aiming because the script had Player1's mouse position stored in it at that very moment.

If it wasn't obvious, I'm very new to scripting and this both had me curious and feels like a detail I should figure out now before I run into issues later. Though I haven't had much luck on looking this up myself.

0
u can use BlindableFunctions or RemoteFunctions PepeElToro41 132 — 4y

1 answer

Log in to vote
0
Answered by
Fifkee 2017 Community Moderator Moderation Voter
4 years ago

You use RemoteEvents. Using RemoteEvents will allow the player to make specific requests to the server. At the same time, this will allow the server to execute multiple requests from different players. It's like they're in completely different working environments.

Let's have this example:

Event.OnServerEvent:Connect(function(p)
    print(p.Name, 'has invoked the RemoteEvent")
end);

And two players call it on the exact same picosecond (extremely unlikely--higher chance of getting struck by lightning).

It would print both at (basically) the same time.

0
Yea. I've been using remote events and having been trying to keep things a bit tidy by calling upon a single script rather than copy pasting the same script onto everyone. Just wasn't sure if this would cause some issues later on that I'd need to be aware of. Thank you. XxTrueDemonxX 362 — 4y
Ad

Answer this question