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

When I test my game in the studio,the players countdown gui stops at 14,any suggestions?

Asked by 4 years ago
Edited 4 years ago

My script is

while wait() do
    if Players.Value >= 2 then

        for i = 15, 1, -1 do
            StatusBar.Text = "Round begins in " .. i
            wait(1)
        end

        for i = 240, 1, -1 do
            Timer.Text = "Time: " .. i
            wait(1)
        end

    elseif  Players.Value < 2 then
        StatusBar.Text = "There needs to be more than 1 player to begin the round."

    end
end

Any suggestion on how to make the countdown actually work?

0
Do you have error? NiniBlackJackQc 1562 — 4y
0
There are no errors. Resetname2343 -5 — 4y
0
Actually when the server counts it down and the players join,the countdown for the players get stuck at the number the server was counting when the players joined. Resetname2343 -5 — 4y
0
Is there a way to fix this or I'm just gonna give up? Resetname2343 -5 — 4y
View all comments (6 more)
0
This is messed up, I tried it ._. ISkyLordDoge 37 — 4y
0
And when I tried it from the roblox client with 2 players,it got stuck at 15 Resetname2343 -5 — 4y
0
Yep, you can try a yt video though, ISkyLordDoge 37 — 4y
0
No, youtube videos are garbage. They are almost never at your learning pace and the code is poor quality, and there known for misinformation programmerHere 371 — 4y
0
Well,it sounds cool on paper,but in practice,not really,and it is easier just to give up and never try again. Resetname2343 -5 — 4y
0
And by the way,if you're wonder about the Players.Value,it is an IntValue I made and that adds 1 to it when a players joins,and removes 1 if a player leaves. Resetname2343 -5 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

In workspace, make a script that has "StringValue" module and change the module name to serverTimer

game.Workspace.Script.serverTimer

This is the code you need for the script:

timer = script.serverTimer
local seconds = 100 -- Change the seconds to what ever you like

repeat
    timer.Value = "There are " .. seconds .. " seconds left"
    wait(1)
    seconds = seconds - 1
until seconds == -1 -- It will keep decreasing until it reaches -1

In StarterGui, make a ScreenGui that has a TextLabel inside it. Inside the TextLabel, add a local script

game.StarterGui.ScreenGui.TextLabel.LocalScript

This is the code for the local script:

game.Workspace.serverScript.serverTimer.Changed:Connect(function()
    script.Parent.Text = game.Workspace.serverScript.serverTimer.Value
end)

This works without causing any issues on the server side and the client side because the "StringValue" module is the middle man. Basically the server script changes the value of the "StringValue" module and the local script updates the player's text every time the module is changed. Let me know if you have any questions

EDIT:

You can make changes to the server script and by changing the code into a function:

function createAnouncer(message, timer)
    if (timer == 0) then
        script.ServerTimer.Value = message
        wait(4)
        return 0
    end

    repeat
        local sec = " seconds"

        if (timer == 1) then
            sec = " second"
        end

        script.ServerTimer.Value = message .. timer .. sec
        wait(1)
        timer = timer - 1
    until timer <= -1
end

-- This can help save tons of time and lines of code when you want to change the status of the game
createAnouncer("Intermission for ", 20)
createAnouncer("Choosing map...", 0)
createAnouncer("Choosing monster...", 0)
createAnouncer("Starting game...", 0)
createAnouncer("Survive for ", 150)
createAnouncer("Time has ended! ", 0)
Ad

Answer this question