How to make global question for answer

I would like to make it so I pick a random math expression to solve which would broadcast it for every active server and any player in any server would be able to answer it for a reward as well as a shout out.

utilize messaging service

example (there can 100% be race conditions):

local MessagingService = game:GetService("MessagingService")

-- use Random or math.random
local expression = "5(2)"
local expressionAnswer = 10

MessagingService:SubscribeAsync("expression", function(expression, answer)
  -- use an alert system here, or some sort of ui
  -- SOLVE FOR REWARDS! {expression}
end)

MessagingService:SubscribeAsync("expressionAnswered", function(username, expression)
  -- use an alert system here, or some sort of ui
  -- {username} answered {expression} correctly!
end)

MessagingService:PublishAsync("expression", expression, expressionAnswer)
2 Likes

You probably want to pick a single server that acts as the question generator, and tells everyone else about it.

One way to do this: you could have all the servers broadcast their game.JobId to each other and have the one whose JobId is the lowest number (or you could use the one that’s been running the longest or something) be the leader.

Detect when the leader is shutting down, so you can change who the new leader is.

Just remember that server-to-server messages are not guaranteed to reach their destination, so you’ll have to program the reliability in yourself.

This guy looks to have implemented something similar, although I can’t personally vouch for its robustness.

Edit: meant to reply to @Philipceo90

3 Likes

Thanks for linking my resource! Granted it’s a bit old, but should work. It will probably need to be re-made to be a bit more modern on the post itself and the resource.