Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help With Gui Countdown?

Asked by
Scootakip 299 Moderation Voter
9 years ago
for i, player in ipairs(game.Players:GetChildren()) do
SGGUI = Instance.new("ScreenGui")
SGGUI.Parent = script.Parent:findFirstChild("tpscript") --Change this to the name of your script
SGGUIT = Instance.new("TextBox")
SGGUIT.Parent = SGGUI
SGGUIT.Size = UDim2.new(.25, 0, .1, 0) --Change this to whatever you want the size to be
SGGUIT.Font = "SourceSansBold" --Change this to whatever you want the font to be
SGGUIT.FontSize = "Size18" --Change this to whatever you want the font size to be
SGGUIT.BackgroundColor3 = Color3.new(.128, .128, .128) --Change this to whatever you want the background color to be
SGGUIT.TextColor3 = Color3.new(1,1,1)
SGGUI.Parent = player.PlayerGui

beep.Pitch = .5

SGGUIT.Text = "Game Starting in 5"
beep:Play()
wait(1)
SGGUIT.Text = "Game Starting in 4"
beep:Play()
wait(1)
SGGUIT.Text = "Game Starting in 3"
beep:Play()
wait(1)
SGGUIT.Text = "Game Starting in 2"
beep:Play()
wait(1)
SGGUIT.Text = "Game Starting in 1"
beep.Pitch = 1
beep:Play()
wait(1)
SGGUI:Destroy()
end

Basically, before the round starts a Gui pops up and has a number count down from 5 to 1. It works fine on its own, but when there is more than one player, not every player gets the gui at the same time, instead it gives each player the gui and countdown individually. Basically, once the gui counts down and destroys for player one, it will then go to player two, rather than doing both players at the same time. Can someone help me fix this issue, it'll be a big issue if there are a lot of players in the game.

2 answers

Log in to vote
0
Answered by 9 years ago

I would reccoment putting a gui in the lighting set to correct proportions and such then Cloning it into player's PlayerGui.

Script that would go into the Gui:

local inst = script.Parent --The text or whatever
wait()
for a=5,0, -1 do 

    inst.Text =  "Game Starting In  "..a.."" 
    wait(1) 
end 
script.Parent.Parent:Destroy() --The text thingies parent/ScreenGui

You would just put that gui into lighting and then have this script clone it into the player's PlayerGui. [Which is easy :p]

for _, player in pairs(game.Players:GetChildren()) do
    Gui = {game.Lighting.TimerGui:Clone()}
    wait()   
    Gui[1].Parent = player.PlayerGui
end
wait(3)
script:Remove() --Removes leftover script/Feel free to remove this.

Hope I somehow helped... ;p

0
Why use the table? You can just set Gui to game.Lighting.TimerGui:clone() Tkdriverx 514 — 9y
0
If you had multiple guis CarterTheHippo 120 — 9y
Ad
Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
9 years ago

View the hierarchy here. The actual GUI size, color, etc. can be anything you like. Also, the name of the scripts don't matter, so they can be anything you want.

Make sure you have FilteringEnabled set to true (but it really doesn't have to).

"ServerScript"

local timeValue = game.ReplicatedStorage:WaitForChild("Timer")
local timerActive = false

-- YOUR CODE HERE (MOST LIKELY RANDOM FUNCTIONS, ETC.) --

while true do -- Infinite loop
    -- YOUR CODE HERE (PRE-TIMER) --
    timerActive = true
    timeValue.Value = 60 -- The time it starts with.

    while timerActive do
        wait(1)

        timeValue.Value = timeValue.Value - 1

        if timeValue.Value <= 0 then -- Can also check for other conditions
            timerActive = false -- Stop the loop
        end
    end

    timeValue.Value = -1 -- Clears the client-side timer to just "--:--"
    wait(3) -- Mostly for debugging so the "--:--" can be seen before being reset.

    -- YOUR CODE HERE (POST-TIMER) --
end

-- DO NOT PUT CODE HERE, IT WILL NEVER RUN --

"LocalGui"

local gui = script.Parent
local label = gui:WaitForChild("Background"):WaitForChild("TimerLabel")
local timeValue = game.ReplicatedStorage:WaitForChild("Timer")

function formatTime(input)
    local output

    if type(input) ~= "number" or input < 0 then -- Makes sure it's a number, OR if it's a number and it's a negative number.
        output = "--:--"
    else
        local formatString = "%i:%.2i" -- This is just a formatting string.
        local seconds = math.floor(input % 60)  -- input % (modulo) 60 gets the remainder of the division of input and 60. Ex: input = 65; 65 % 60 is 5
        local minutes = math.floor(input / 60) -- math.floor rounds numbers down towards negative infinity. Just in case input / 60 is a decimal, it becomes a whole number.

        output = formatString:format(minutes, seconds)
        -- The "%.2i" in the formatting string adds leading zeros if the number is less than 10. No conditional if statements needed!
    end

    return output
end

timeValue.Changed:connect(function()
    local timeString = formatTime(timeValue.Value)

    if timeString then
        label.Text = timeString
    end
end)

-- YOUR CODE HERE --

The -- YOUR CODE HERE -- is where your code should go.

I hope this helped. If you have any questions, feel free to contact me or just post a comment on this answer.

Answer this question