-
What do you want to achieve?
I want a countdown of 120 seconds to play during the game and then have the text change to “Times up!”
Kinda like when a player has a timed obby and only x amount of time to complete the obby, then the game will end. In this game, the player has x amount of time to complete as many orders as they can before the timer runs out.
-
What is the issue?
The countdown plays separately from the game. It will first countdown and then the rest of the game will run.
Here’s a video of the issue:
P.S. Ignore the all the random output stuff, it’s just other things in the game that I forgot to remove before recording the video! But you’ll see that it prints the second it’s on.
-
What solutions have you tried so far?
I’ve used ChatGPT to help me figure out what I’m doing wrong but it hasn’t been very useful at all as it gives me different answers, writes completely unrelated code/writes in a different scripting language.
Workspace Set-up
The other Localscripts trigger the ‘Job’ and ‘JobEnd’ RemoteEvents (I haven’t added the ‘JobEnd’ function into the Main script yet though.
Main Script:
I also used 10 seconds instead of 120 so I could test whether the countdown worked
local jobGui = script.Parent
local countdowntext = jobGui.Countdown
local characters = {"Hello Kitty"} -- temporary
while(1) do
script.Parent.Frame.TextButton.LocalScript.Disabled = true
wait(2)
local randomIndex = math.random(1, #characters)
local characterToClone = game.ReplicatedStorage.NPCs[characters[randomIndex]]
local clone = characterToClone:Clone()
local animation = clone:WaitForChild('Animation')
local humanoid = clone:WaitForChild('Humanoid')
clone.Parent = workspace
--Countdown
countdown = 10 --120
while countdown > 0 do
countdown = countdown - 1
countdowntext.Text = countdown
wait(1)
print(countdown)
end
print("STOP!")
countdowntext.Visible = true
countdowntext.Text = "Times up!"
wait(1)
countdowntext.Visible = false
script.Parent.active.Value = 0
local anim = humanoid:LoadAnimation(animation)
anim:Play()
clone.Humanoid:MoveTo(workspace.endo.Position)
wait(1)
anim:Stop()
local ma = math.random(1,4)
if ma == 1 then
clone.Head["1"].Enabled = true
elseif ma == 2 then
clone.Head["2"].Enabled = true
elseif ma == 3 then
clone.Head["3"].Enabled = true
elseif ma == 4 then
clone.Head["4"].Enabled = true
end
local ProximityPromptTriggered = false
-- Wait until player triggers proximity prompt
clone.Head.ProximityPrompt.Triggered:Connect(function()
if clone.Head["1"].Enabled == true then
if game.Players.LocalPlayer.Character:FindFirstChild("coffee") then --these are swapped btw, 1 = coffee but the tool = donut, it works tho!
ProximityPromptTriggered = true
clone.Head["TY"].Enabled = true
clone.Head.ProximityPrompt.Enabled = false
else
print("You don't have the correct tool!")
ProximityPromptTriggered = false
clone.Head["1"].Enabled = false
clone.Head["NO"].Enabled = true
wait(2)
clone.Head["NO"].Enabled = false
clone.Head["1"].Enabled = true
end
elseif clone.Head["2"].Enabled == true then
if game.Players.LocalPlayer.Character:FindFirstChild("doughnut") then
ProximityPromptTriggered = true
clone.Head["TY"].Enabled = true
clone.Head.ProximityPrompt.Enabled = false
else
print("You don't have the correct tool!")
ProximityPromptTriggered = false
clone.Head["2"].Enabled = false
clone.Head["NO"].Enabled = true
wait(2)
clone.Head["NO"].Enabled = false
clone.Head["2"].Enabled = true
end
elseif clone.Head["3"].Enabled == true then
if game.Players.LocalPlayer.Character:FindFirstChild("green tea") then
ProximityPromptTriggered = true
clone.Head["TY"].Enabled = true
clone.Head.ProximityPrompt.Enabled = false
else
print("You don't have the correct tool!")
ProximityPromptTriggered = false
clone.Head["3"].Enabled = false
clone.Head["NO"].Enabled = true
wait(2)
clone.Head["NO"].Enabled = false
clone.Head["3"].Enabled = true
end
elseif clone.Head["4"].Enabled == true then
if game.Players.LocalPlayer.Character:FindFirstChild("muffin") then
ProximityPromptTriggered = true
clone.Head["TY"].Enabled = true
clone.Head.ProximityPrompt.Enabled = false
else
print("You don't have the correct tool!")
ProximityPromptTriggered = false
clone.Head["4"].Enabled = false
clone.Head["NO"].Enabled = true
wait(2)
clone.Head["NO"].Enabled = false
clone.Head["4"].Enabled = true
end
end
end)
while not ProximityPromptTriggered do
wait()
end
if clone.Head["1"].Enabled == true then
clone.Head["1"].Enabled = false
elseif clone.Head["2"].Enabled == true then
clone.Head["2"].Enabled = false
elseif clone.Head["3"].Enabled == true then
clone.Head["3"].Enabled = false
elseif clone.Head["4"].Enabled == true then
clone.Head["4"].Enabled = false
end
clone.Head["TY"].Enabled = true
anim:Play()
clone.Humanoid:MoveTo(workspace.start.Position)
wait(2)
anim:Stop()
if clone.Head["1"].Enabled == true then
clone.Head["1"].Enabled = false
elseif clone.Head["2"].Enabled == true then
clone.Head["2"].Enabled = false
elseif clone.Head["3"].Enabled == true then
clone.Head["3"].Enabled = false
elseif clone.Head["4"].Enabled == true then
clone.Head["4"].Enabled = false
elseif clone.Head["TY"].Enabled == true then
clone.Head["TY"].Enabled = false
end
clone:Destroy()
wait(2)
end
ServerScriptService Script:
This script is for the initial 5 second countdown!
game.Players.PlayerAdded:Connect(function(player)
local countdown = 5
local jobGui = player.PlayerGui
local countdowntext = jobGui:WaitForChild("Job").Countdown
countdowntext.Visible = true
countdowntext.Text = "Starting game in: " .. countdown
print("Starting game in: " .. countdown)
while countdown > 0 do
countdown = countdown - 1
countdowntext.Text = "Starting game in: " .. countdown
wait(1)
print(countdown)
end
countdowntext.Text = "GO!"
print("GO!")
wait(.5)
game.ReplicatedStorage.Job:FireClient(player)
end)