How Do I Make A Script Run When the Game Starts, Rather than When the Player Joins?

So I’ve got this script (see below) and I’d like to know how to make the script start running as soon as the game starts. It appears that as of now it starts when each respective player joins. Can anyone help me out?

Script

while true do
wait(60)

script.Parent.Fade_Script.Disabled = false

script.Parent.Sword_Spin_Script.Disabled = false
wait(7.5)
end
1 Like

I don’t really understand, do you want the script to run as soon as the server is created or as soon as the “Intermission” is over?

1 Like

I’d like the script to begin as soon as the server is created.

Leaving your script as it is should (in theory) run as soon as the server is created.

Roblox creates a server for an experience whenever a player enters the game and there are no available servers, so the script will run as soon as a player creates a server. Looking at your script, It shouldn’t restart if another player joins, where did you place the script?

I placed the script in ServerScriptService.

In that case it should be fine? You are using a while true loop, so the script will keep repeating itself after it finished the loop, beside that it should run as soon as a new server is created.

Well that’s what I thought, however, I tested this in-game and that wasn’t the case. I joined the server (initiating the script) and my cousin joined around 20 seconds later. The script functioned as it should for me, but it was delayed for my cousin (around 20 seconds delayed).

Is the script a Local Script? This might be the issue.

1 Like

Nope, the script is just a regular script. :neutral_face:

What do you mean by “delayed”? Did you see the map change but he (your cousin) wouldn’t see them before a lapse of 20 seconds?

Hang on, just realized that you were viewing the wrong script haha. So sorry for the wasted time friend. This is the script that is causing all of the trouble (see below). It is a LocalScript located in ScreenGui.

while true do
wait(60)

script.Parent.Fade_Script.Disabled = false

script.Parent.Sword_Spin_Script.Disabled = false
wait(7.5)
end
1 Like

this is a local script therefore it will start the moment a player joins and only viewable in their perspective so it won’t be globally present to everyone else

2 Likes

It’s okay, mistakes are human.

If it’s a Local Script, it will run on the client, meaning it won’t run at the same interval for everyone. If you want the GUI to appear the same on everyone, you could use a Remote Event with FireAllClients() or simply makeit a server script.

3 Likes

Additional note, you might wanna replace all the wait() with task.wait(), as wait() is deprecated and Task Librairies are more accurate.

2 Likes

Thanks for being understanding. :slight_smile:

So I can just switch the script to a regular script and it’ll function as I intended, correct? Meaning it’ll begin as soon as the server is created rather than when each respective player joins.

Thanks for the heads up! :slight_smile:

The script will run on the server, so an issue you might have is that players who joined 60 seconds after the server’s creation won’t have to wait for the Fade & Sword Spin scripts to enable, you could fix this using a PlayerAdded function and twisting a bit how the Sword Spin, etc. script works.

1 Like

So Player_1 joins, initiating the script. Player_2 joins 55 seconds later. Will he see the Fade_Script 5 seconds after joining?

Okay, let me rephrase this.

If you make a server script, it should go like this.

Server creates itselfServer script starts the wait(60) loopPlayer 1 joins60 seconds later, the Fade Script enables and playsPlayer 2 joinsPlayer 2 joined too late, so he won’t see the Fade Script for the firs time. He has to wait for the loop to restart to see the Fade Script

1 Like

Simple solution, if the Fade Script is just supposed to mark a transition from the old map to the new map, you could use a Remote Event so when the map changes, you fire the remotes to all clients and create a Fade effect on a Local Script.

https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

1 Like

Oh ok. But Player 2’s timing won’t be off, and on the next go around (and from then on), they will both view the Fade Script at the same time, correct?