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

My count down text It's not working, How to solve it?

Asked by 6 years ago
Edited 6 years ago

I maked a power-up in the game when you touch gives you speed, everything It's okay, but the text Isn't counting down when touched.

i make a script like this.

game.StarterGui.CounterSpeedGUI.TextLabel.Visible = false
local counter = game.StarterGui.CounterSpeedGUI.TextLabel

function OnTouch()
    script.Disabled = true
    wait()
    game.Players.LocalPlayer.PlayerGui.CounterSpeedGUI.TextLabel.Visible = true
    wait(1)
    counter.Text = "9"
    wait(1)
    counter.Text = "8"
    wait(1)
    counter.Text = "7"
    wait(1)
    counter.Text = "6"
    wait(1)
    counter.Text = "5"
    wait(1)
    counter.Text = "4"
    wait(1)
    counter.Text = "3"
    wait(1)
    counter.Text = "2"
    wait(1)
    counter.Text = "1"
    wait(1)
    game.Players.LocalPlayer.PlayerGui.CounterSpeedGUI.TextLabel.Visible = false
    counter.Text = "10"
    wait()
    script.Disabled = false
end

script.Parent.Touched:connect(OnTouch)
0
You're changing StarterGui's, not the player's. TheeDeathCaster 2368 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

Your issue most probably is because you are refferencing your GUI in the StarterGUI service on studio.

Remember, the GUI's that you have in StarterGUI get cloned to the player's PlayerGUI folder meaning that the changeds have to be done in the player's PlayerGui folder. Any GUI that you want for example to countdown has to be modified in the player's PlayerGui folder a.k.a the cloned GUI from StarterGUI.

Breaking it down in simple terms:

You apply the scripting to the GUI's that are in the PlayerGUI folder of the player, not the StarterGui.

Your code would be as follows:

local plr = game.Players.LocalPlayer;
local plrGui = plr:WaitForChild("PlayerGui");
speedGUI = plrGui:WaitForChild("SpeedGUI")
countdownGUI = speedGUI:WaitForChild("CounterSpeedGUI");

LabelCount = countdownGUI:WaitForChild("CountLabel");
TouchPart = workspace:WaitForChild("TouchPart");

-- Making sure everything is loaded ^.

countdownGUI.Visible = false; -- Visible false
local buttonPressed = false; -- Simple Debounce

TouchPart.Touched:Connect(function(hit)
    countdownGUI.Visible = true;

    if not buttonPressed then
        buttonPressed = true;
        for i = 10, 1, -1 do -- Loop to do the countdown.
            print("Counting down ".. i);
            LabelCount.Text = "Cooldown: " ..i;
            wait(1);
        end
        LabelCount.Text = "Cooldown: " ..10;
        countdownGUI.Visible = false;
        buttonPressed = false;
    end
end)

Remember that doing a for loop is way easier than doing wait() & changing the text manually!

Refference links on the basic stuff used in this code:

http://wiki.roblox.com/index.php?title=Debounce

http://wiki.roblox.com/index.php?title=Loops

http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched

Ad
Log in to vote
-2
Answered by
Felktor -8
6 years ago

I feel like the reason is the fact that you put this:

local counter = game.StarterGui.CounterSpeedGUI.TextLabel

when it should be this:

local counter = game.StarterGui.CounterSpeedGUI.TextLabel.Text
0
(On line 1) Felktor -8 — 6y

Answer this question