Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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()

2 comments

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.

0

30 minutes in game

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks, wow thats actually brilliant man and I actually learnt from that.

This discussion is preserved as it was. New answers, comments, and votes are closed.