Run a function while no servers are open

  1. What do you want to achieve? Keep it simple and clear!
    So I have a timer but it goes of at a certain point. How would I make it so that
    when it finishes I can get notified. The experience is private though and no servers
    are running

  2. What is the issue? Include screenshots / videos if possible!
    Well how do I do that. I don’t need full code just the bases of how I would do
    something like this.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? Looked around on DevForums and docs. Found nothing however I tried to use a proxy but I have a very limited knowledge of javascript.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Does this but while no one is playing the game

local times = 99999999
while times > 0 do
 times-=1
 task.wait(1)
end

--notify me with a webhook

Any helps appreciated thanks!

You can’t run a script without an active server

1 Like

Ok do you have any other suggestions then?

The only thing it comes up to my mind is if there are no servers, and someone is the first one joining it, it will show up “Joining for an available server. Retying(1, 2, 3…)”. Basically, once the first player joins the server run up the script you want and then while the server has people on it the script to work as normal.

What I want to say is, if there are no servers, it’s impossible to be executed. The thing you should do is once the server is initiated the first thing to be done once the server is opened is to run the script you want. Otherwise I don’t think there is anything to do.

Could i offload it to a proxy and do it there?

You could try doing a workaround with a proxy probably.

Do you have any idea to what the javascript code would be?

Unfortunately I have not tried yet something like this, but maybe you could check in the #help-and-feedback:scripting-support category as there are lots of posts which could probably help you. However I am sorry not to be able to help you with this exactly.

Like you said, create an external server that does that task for you and simply add wait function for the script for the server and then host it, on your device or in the cloud.

Think i found the solution I use a package called node-cron in a glitch server then offload the function to there where it sends a message to my server when it’s done

const xhr = require("xhr2")
const http = require("http")

let server = http.createServer(function(In,Out)
{
 //Handle the request over here
 Out.write(getResponse(In)) //Send whether the request has been successful
 Out.end()
})

server.listen(8080)

while (true) {
  //Handle timers that will be added to the list if request is successful 
}

image

xhr basically returns XMLHttpRequest class and is useful for requests to the discord API for webhooks.

Thanks. I will look into this might be helpful for the glitch tutorial I going to make

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.