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

Can a server script run two threads at the same time (not wanted)?

Asked by
TomsGames 225 Moderation Voter
4 years ago

So I'm writing a script to start the round to a game when a child is added to the "PlayerObjects" folder. An object is added to the PlayerObjects folder when a player joins - there is a server script which will create the related folder & objects and will then place it into the PlayerObjects folder.

What I am worried about is this: If two players join at the same time and two objects are created in the PlayerObjects folder, will they be created simultaneously? Is there any possibility that the server script listening to ChildAdded will begin running for one object, and before it is finished it will spin off another thread for the second child added?

This is logic that might break the game, so I am adding checks by creating a boolean value as a child of the script that it checks to see if the script itself is already running. I don't know if I'm overdoing it or not - does anybody know if this is a reasonable concern?

1 answer

Log in to vote
3
Answered by
Elixcore 1337 Moderation Voter
4 years ago

when you connect to an event it automatically creates a new thread every single time the event is fired, they will not overlap each other and stop in case 2 players join at the same time unless they use the same upvalues or such.

1
Thank you, i rushed my answer and just gave the point blank answer regarding the title thread just read the description of it and you seemed to have posted it before i did haha, upvoted. User#31525 30 — 4y
Ad

Answer this question