Time of the day changes for 1 second but then returns back to the default time

I’m quite new to scripting, so my script might be messy, but basically, the way the gui works, is you can type in “Night”, you press confirm and the game time changes.

Also, ignore the part that says 00:00:00

I then test it out, it works but then switches back to the time i set it in studio.
https://gyazo.com/ca19853c9d2f4c03eb0c1a130a6ea4fb

Script

``lua

local NotSpecific = script.Parent.ObjectiveTime
local SpecificTime = script.Parent.SpecificTime

local Confirm = script.Parent.Confirm

local ClockTime = game.Lighting.ClockTime

Confirm.MouseButton1Click:Connect(function()

if NotSpecific.Text == "Night" then

game.Lighting.ClockTime = 21

elseif NotSpecific.Text == "Evening" then

game.Lighting.ClockTime = 18

elseif NotSpecific.Text == "Afternoon" then
	
	game.Lighting.ClockTime = 17
	
elseif NotSpecific.Text == "Day" then
	
	game.Lighting.ClockTime = 12
	
elseif NotSpecific.Text == "Morning" then
	
	game.Lighting.ClockTime = 7
	

end

end)


GUI explorer

GUI

Lighting Properties

Lighting

Any help would be appreciated, if you need more details just ask me, thanks :slight_smile:

Do you have an other scripts that change the time of day manually. Like any loops that increase the time every second? If you had a loop that changed the time on the server then it would cause this issue.

Please format your code better so it is easier to read. You do not need to use the ```lua specifier like on Discord, as on the DevForum, three ` keys by themselves do the job just fine, like in this example:

```
function Test()

end 
```

I’m having some problems reading it but I remember that if you try tweening time to positive numbers it goes forward, else it goes backwards

Tween from 18 hours to 30 hours, makes go from 6pm to 6am smoothly forward (Passing through night)

Tween from 3 hours to - 10 hours, makes go from 3am to 2pm smoothly backwards (Passing through night)

I think most would agree that typing in a word for the time of day seems like a strange way of changing the in-game time. Some immediate problems you face are:

  • People will misspell words, enter an unspecified word, or enter words in the wrong case.

    day
    noon
    Evning
    Nihgt
    MOrning

  • Many players do not know English.

A better idea is to simply use a slider for this purpose. I created a standalone day/night slider for some of my games, including Doomspire Brickbattle. Because I made it strictly for myself, implementing it isn’t exactly optimal for other developers at the moment, but I will show how to use it here.

  1. Insert this model to have the system in your game.

  2. Put this LocalScript into game.StarterPlayer.StarterPlayerScripts to make it so typing /time in the chat will open the menu.

Opening the menu with a chat command is the only pre-set method I created for others to use, but I imagine you won’t want to use this method. Hence why I separated the system script from the opener script—you can create your own opening method with this, too.

Take the _G function from inside the chat opener LocalScript and implement it into a GUI, perhaps being displayed when you click a button. The only issue here is that the slider GUI itself was made by me and probably does not fit the same aesthetic style you have in your game. Changing this would require forking the module, which can be retrieved from within the script in the first link above.

Here’s how it works, from a development gif when I made it a few months ago: https://gyazo.com/8955f113c571efb0e97a1afc0f247509