Hello people!
So I have a message that is played 21 seconds after someone joins. The problem is, I can't stop the final message from being only a couple seconds and then disappearing.
local msg = Instance.new("Message") msg.Parent = Workspace wait (21) msg.Text = "The game will be starting in..." wait (5) msg.Text = "5" wait (1) msg.Text = "4" wait (1) msg.Text = "3" wait (1) msg.Text = "2" wait (1) msg.Text = "1" wait (1) msg.Text = "TELEPORTING PLAYERS" wait (1)
I have tried putting "end" at the end. But it won't show up in the first place.
local msg = Instance.new("Message") msg.Parent = Workspace wait (21) msg.Text = "The game will be starting in..." wait (5) msg.Text = "5" wait (1) msg.Text = "4" wait (1) msg.Text = "3" wait (1) msg.Text = "2" wait (1) msg.Text = "1" wait (1) msg.Text = "TELEPORTING PLAYERS" wait (1) end
I've also tried this
local msg = Instance.new("Message") msg.Parent = Workspace wait (21) msg.Text = "The game will be starting in..." wait (5) msg.Text = "5" wait (1) msg.Text = "4" wait (1) msg.Text = "3" wait (1) msg.Text = "2" wait (1) msg.Text = "1" wait (1) msg.Text = "TELEPORTING PLAYERS" wait (1) m:Remove() end
Help and thanks.
This is based on the assumption that there are no other parts to this script. So, technically, yes, your script would play, but only after the first person to ever start that particular server joins the game. It will never play again after that. Also, your script doesn't correctly start when a player joins, it starts when the server starts. This means that the player most likely won't see the entire message since your script will load before the player does. For a very basic setup, you're going to need tick() to account for the time passed since the server started (since someone did join to start it) and a while loop to keep running your game. You also need to take into account that the first person who joined may have left within 21 seconds of your first message, so go ahead and make sure there's someone even in the game to start it.
local msg = Instance.new("Message", workspace) local minimumPlayers = 1 local startCount = 5 local stopCount = 0 local incBy = -1 -- You can also do this => local startCount, stopCount, incBy = 5, 0, -1 local pause = 1 -- your wait between messages local serverStartTime = tick() local delayedStart = 21 local function start() msg.Parent = workspace for num = startCount, stopCount, incBy do -- returns true since it's the first run local firstMessage = (num == startCount) -- if firstMessage == true then wait is 5s else wait is 1s local waitTime = firstMessage and 5 or pause -- %s inserts your variable with string.format(), in this case "num" msg.Text = string.format( "The game will be starting in %s", num) wait(waitTime) end -- parent the message to nil, so you can re-parent it back when you need it msg.Parent = nil -- move on to next function, else it goes back to the while loop end while true do -- Comes back to this check after all functions have completed / game has ended local timeUntilStartable = ( tick() - serverStartTime ) -- prints the delay countdown in the output print(timeUntilStartable < delayedStart and math.floor(timeUntilStartable) or "We can start when there are enough players") if game.Players.NumPlayers >= minimumPlayers and timeUntilStartable >= delayedStart then start() end wait(1) end