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

How do I get a text label change subject every 30 minutes? For some reason this does not work.

Asked by 6 years ago
Subjects = {"Math","English","Computer Science" ,"Drama","Geography", 
        "Chemistry","Physics","Physical Education","Economics",
        "Arts","Biology","History","French"}


function subject()
if game.Lighting.TimeOfDay == "08:00:00" then
    for i = 1,6 do
    while wait(10) do
            local tempsub = Subjects[math.random(1,#Subjects)]
            script.Parent.Text = "Subject " .. tempsub
            end
        end
    end
end

subject()
0
30 minutes in real life or 30 minutes in game? Another thing, if the time is any time other than "08:00:00" the loop WILL NOT run as well so make sure for that as well. Tomstah 401 — 6y
0
30 minutes in game DrInfinitum 4 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Three problems,

1) I'm not sure if using the "TimeOfDay" property of lighting is the most effective way of finding the time of day. Instead, i would recommend using the function "GetMinutesAfterMidnight()". You can learn more about that here "http://wiki.roblox.com/index.php?title=Making_a_Day/Night_Cycle"

2) I'm not sure if you were intending this or not. but there is no function to let the script know to repeat until this condition is met. Thus making it run only once and not checking when it's 8 AM.

3) I didn't know if you meant realtime or game time, so I went with real-time 30mins

Subjects = {"Math","English","Computer Science" ,"Drama","Geography", 
        "Chemistry","Physics","Physical Education","Economics",
        "Arts","Biology","History","French"}


function SubjectChange()
    while true do 
    local tempsub = Subjects[math.random(1,#Subjects)]
    script.Parent.Text = "Subject " .. tempsub
    wait(1800) --1800 is 30mins in seconds.
        if game.Lighting:GetMinutesAfterMidnight() == 15 * 60 then -- this is if you want the subject changes to end at 3PM (or at all). 
            break -- Breaks the loop
        end
    end
end

while wait() do --You can also use "game.Lighting.Changed:connect(function()" for if any property of lighting is changed but unfortunately, this dosen't work on spawn. 
    if game.Lighting:GetMinutesAfterMidnight() == 8 * 60 then -- 8AM
        SubjectChange()
    end
end

I also added a condition for when it reaches a certain time the loop ends. Hopefully, this helped.

0
Thanks, wow thats actually brilliant man and I actually learnt from that. DrInfinitum 4 — 6y
Ad

Answer this question