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

Labels not updating, how do I fix it?

Asked by 3 years ago

I've created a script that will auto update the labels of a GUI. I've tried both Script and LocalScript, yet nothing is working for me. There are no errors whatsoever, which makes me think that the script isn't even running at all.

Here is my code if you need it:

--[[

-- INFO --

Weather

0 = Normal
1 = Rain
2 = Thunderstorm

]]

-- Settings --

local songs = { -- All songs must be 60 seconds or longer (even 59.9999 is not recommended)
    -- Normal
    {Song = script.Day, Weather = 0, TimeOfDay = {"Dawn","Noon"}},
    {Song = script.Sunset, Weather = 0, TimeOfDay = {"Dusk"}},
    {Song = script.Night, Weather = 0, TimeOfDay = {"Night"}},

    -- Rain
    {Song = script.MorningRain, Weather = 1, TimeOfDay = {"Dawn"}},
    {Song = script.Rain, Weather = 1, TimeOfDay = {"Noon","Evening"}},
    {Song = script.NightRain, Weather = 1, TimeOfDay = {"Night"}},

    -- Thunder
    {Song = script.Thunderstorm, Weather = 2, TimeOfDay = {"Dawn","Noon","Dusk","Night"}}
}

























-- Script --



game:GetService("RunService").Heartbeat:Wait()



local RS = game:GetService("RunService")

local dayLabel = script.Parent.Day
local timeOfDayLabel = script.Parent.TimeOfDay

local music = script.Parent.Music

RS.Stepped:connect(function()
    local timeOfDay = "Night"
    local weatherString = ""

    if (game.Lighting.ClockTime > -1) and (game.Lighting.ClockTime < 6) then
        timeOfDay = "Night"
    elseif (game.Lighting.ClockTime < 12) then
        timeOfDay = "Dawn"
    elseif (game.Lighting.ClockTime < 18) then
        timeOfDay = "Noon"
    elseif (game.Lighting.ClockTime < 24) then
        timeOfDay = "Dusk"
    end

    if game.Lighting.Weather.Value == 1 then
        weatherString = " (Rain)"
    elseif game.Lighting.Weather.Value == 2 then
        weatherString = " (Thunder)"
    end

    dayLabel = "Day "..game.Lighting.Day.Value
    timeOfDayLabel = timeOfDay..weatherString

    for _,i in pairs(songs)do
        if (i.Weather == game.Lighting.Weather.Value) then
            local found = false
            for _,v in pairs(i.TimeOfDay)do
                if v == game.Lighting.TimeOfDay.Value then
                    found = true
                    music.SoundId = i.Song.SoundId
                end
            end
            if found == true then break end
        end
    end

    if music.IsPlaying == false then
        music:Play()
    end
end)

Thanks!

0
"which makes me think that the script isn't even running at all" Have you tried adding a print at the top of your script to see if it runs or not? brokenVectors 525 — 3y

1 answer

Log in to vote
1
Answered by
tjtorin 172
3 years ago

The problem is that you are doing:

timeOfDayLabel = timeOfDay..weatherString

when you need to do:

timeOfDayLabel.Text = timeOfDay..weatherString

The reason for that is because the way you are doing it is changing the variable completely which is also why you are not getting any errors because technically it is correct.

0
Ohhh... CrastificeDude612 71 — 3y
0
If this answered your question, please mark this as the answer. @CrastificeDude612 ReadyHappiness 109 — 3y
0
Why is it not letting me? CrastificeDude612 71 — 3y
0
Finally... CrastificeDude612 71 — 3y
Ad

Answer this question