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

Loop of a script related to game time not working?

Asked by
Time_URSS 146
5 years ago

Greetings. I've a script that shows a virtual time in a game, but it doesn't work. The script is this:

-- [Time]

local HoursD = script.Parent.Hours.HoursD.Value
local HoursU = script.Parent.Hours.HoursU.Value
local MinutesD = script.Parent.Minutes.MinutesD.Value
local MinutesU = script.Parent.Minutes.MinutesU.Value
local SecondsD = script.Parent.Seconds.SecondsD.Value
local SecondsU = script.Parent.Seconds.SecondsU.Value
local TimeLabel = script.Parent.Text

-- [Loop]

while true do
    SecondsU = SecondsU + 1
    wait(1)
    TimeLabel = HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU
    print(HoursD,HoursU,MinutesD,MinutesU,SecondsD,SecondsU)
    if SecondsU == 9 then
        wait(1)
        SecondsU = 0
        SecondsD = SecondsD + 1
        TimeLabel = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU)
    end
    if SecondsD == 5 and SecondsU == 9 then
        wait(1)
        SecondsU,SecondsD = 0
        MinutesU = MinutesU + 1
        TimeLabel = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU)
    end
    if MinutesU == 9 then
        MinutesU = 0
        MinutesD = MinutesD + 1
        TimeLabel = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU)
    end
    if MinutesD == 5 and MinutesU == 9 and SecondsD == 5 and SecondsU == 9 then
        MinutesD,MinutesU = 0
        HoursU = HoursU + 1
        TimeLabel = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU)
    end
    if HoursU == 9 then
        HoursU = 0
        HoursD = HoursD + 1
        TimeLabel = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU)
    end
    if HoursD == 2 and HoursU == 3 and MinutesD == 5 and MinutesU == 9 and SecondsD == 5 and SecondsU == 9 then
        HoursD = 0
        HoursU = 0
        MinutesD = 0
        MinutesU = 0
        SecondsD = 0
        SecondsU = 0
        TimeLabel = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU)
    end
end

But, when I start the game, the loop isn't starting: The textlabel remains as 00:00:00, and I don't see anything in the output. How can I solve it?

0
what am I looking at ._. greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

The problem is that the Variable "TimeLabel" is set to script.Parent.Text. So by doing TimeLabel = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU) You are setting the Variable. Instead do local TimeLabel = script.Parent and change the Text using TimeLabel.Text = (HoursD..HoursU..":"..MinutesD..MinutesU..":"..SecondsD..SecondsU)

0
oh, ok Time_URSS 146 — 5y
Ad

Answer this question