I've been trying to make a minigame kit for me and other people to use, and I thought it would be a good way to practice scripting since I'm a beginner. I've gotten down the times (like how long each round lasts, and intermission) and what I'm working on now is the count down GUI.
-- K E Y ~ [CE: Can edit] - [DE: Don't edit] - [CD: Can delete] --[Starter Variables] local MaxRoundTimeInSeconds = 10 --The maximum round time (in seconds) until intermission. [CE] local IntermissionTimeInSeconds = 5 -- The intermission time (in seconds) until round begins. [CE] local RoundStartTime -- Is set depending on when the round begins. [DE] local IntermissionStartTime -- Is set depending on when the intermission begins. [DE] --[Function that defines the beginning of the round] local function initialize() -- Function name "initialize" to represent beginning of round. [DE] RoundStartTime = tick() -- The round start time is set by the current time. [DE] end --[Function that defines beginning of intermission] local function initialize2() IntermissionStartTime = tick() end --[Functions & Variables for your round] local function YourFunction() -- This is the name of your function! [CE/CD] local YourVariable = ("This is a string!") -- This is a variable that holds a string value, but you can change that. [CE/CD] print (YourVariable) -- This is what your function does. [CE/CD] end --[The round in action] while true do -- "while true do" creates a loop. [DE] initialize() -- "initialize" function is fired. [DE] repeat -- Tells to repeat whatever is below until something stops it. [DE] local currentTime=tick() -- The variable, "currentTime", is created.[DE] local TimeSinceGameStarted= currentTime - RoundStartTime -- Defines "TimeSinceGameStarted" as the current time subtracted by the time when the round started. [DE] --[GUI in action] local countdown = game.StarterGui.Timer.Countdown countdown.Value.Value = MaxRoundTimeInSeconds for i=1, MaxRoundTimeInSeconds do countdown.Value.Value = countdown.Value.Value - 1 countdown.Text = countdown.Value.Value wait(1) end --[Functions fired in round] YourFunction() -- This fires the function you created. Rename this if you renamed the previous "YourFunction". [CE] wait(0.25) -- Wait one fourth of a second before repeating again. until TimeSinceGameStarted > MaxRoundTimeInSeconds -- Repeat until the max round time in seconds is reached... wait(IntermissionTimeInSeconds) --... Wait the intermission time that was set. end
(The comments is for people who use it once I'm done making the kit)
The "GUI in action" section is the place where you should focus. I don't get what's wrong with it. When I test the game out, the gui's text says "8" and stays that way, as the value that's inside that gui counts down starting at 0, going into the negatives. Can someone try to figure out what I did wrong? I tried many ways and none of them seems to work!
Your code is not changing the timer on the player's screen. It is changing the timer located in game.StarterGui.
If you want to change the one of the player's screen you'll need to do
plr.PlayerGui.Timer.Countdown.Text = numberValue
Remember that when a player spawns in all of the contents of StarterGui
are cloned into each their own personal PlayerGui
found in game.Players.MartingaleThreat.PlayerGui
, and every time the character respawns a new one from StarterGui
is cloned and placed in PlayerGui
once again.
So what you'll want to do to fix this is:
for i=1, MaxRoundTimeInSeconds do
for _, plr in pairs(game:GetService("Players"):GetPlayers()) do
plr.PlayerGui.Countdown.Value.Value = plr.PlayerGui.Countdown.Value.Value - 1
plr.PlayerGui.Countdown.Text = plr.PlayerGui.Countdown.Value.Value
end
starterCountdown.Value.Value = starterCountdown.Value.Value - 1 starterCountdown.Text = starterCountdown.Value.Value wait(1)
end
So we are changing the time of every PlayerGui
in the game and changing the time of the countdown in the StarterGui
so that when you spawn you get the updated time.