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

How do I make This TextLabel Display the Current Event based on the ClockTime in game?

Asked by 1 year ago
Edited 1 year ago

In my game is a UI in the right top corner of the screen that displays the current time (7:00 AM, 10:30 AM) and below it is the current activity going on at school (Classtime, Lunchtime) I looked around to find some scripts that could help and I found this one script but I don't know certain terminology and details so I don't know exactly what to do with the script. I don't know whether it should be a LocalScript or not or any of that.

The UI is a ScreenGui and inside of it are Two Text Labels, one named CurrentTime, and the other named CurrentActivity. Inside of CurrentActivity is where this script is located which is why in the script I put "script.Parent.Text = Str" because I want the Text of the Parent (The CurrentActivity TextLabel) to display the text. But it also says to assign "Str" to something and I don't know what.

Anyways, here's the script, if anyone knows what to do, please let me know!

local Schedule = {
    ["6.50"] = "Before School",
    ["7"] = "Before Class",
    ["8.50"] = "Classtime",
    ["13"] = "Lunchtime",
    ["13.50"] = "Classtime",
    ["15.50"] = "After School",
    ["20"] = "Nighttime"
}
--Create a library which stores what you want to to be on the schedule
--ClockTime uses 24/h time, so 10pm would be 22
--Libraries act weird when you use numbers as the indexes, so I turn them to strings

local IntTime = Instance.new("IntValue", script)
IntTime.Changed:Connect(function()
    local Str = Schedule[tostring(game.Lighting.ClockTime)]
    --Assign 'Str' to whatever is stored in the library under the current clocktime, if there is something
    if Str then
        --If this conditional passes, then something was found in the library
        script.Parent.Text = Str
    end
end)

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    --Fires when ClockTime has changed, at all
    IntTime.Value = math.floor(game.Lighting.ClockTime)
end)

Edit: Okay, so the script does work, sort of. The reason it wasn't changing was because I was play testing in Roblox Studio and for some reason it wasn't changing in Roblox Studio but it was when I actually played the game through the Roblox website.

But the problem is, when it says 6.5, that's supposed to be the ClockTime for 6:30, but the Text doesn't change at 6:30, it will only change at 7 to Before Class. I tried changing 6.5 to just 6, but that didn't work either. I also went all the way to 8:30 AM, but it didn't change to Classtime like it was supposed to either. I'm having a difficult time trying to troubleshoot this so if anyone can help, please let me know

Answer this question