So I’m trying to make a GUI which lets a player control the time of day. I’m using a local script which is acting as the communicator between a module script and the GUI itself.
But, I’ve ran into what I imagine as a simple issue to solve; the script does not print the proper input that’s been inputted into the textbox of the GUI.
The local script;
repeat wait() until game.ReplicatedFirst.assetPreloader.loaded.Value == true
local timeThing = require(game.ReplicatedStorage.modules.timeThing)
local weatherController = script.Parent
local timeBox = weatherController.main.timeOfDay.Text
function clickedWeatherToggle()
print 'clicked'
if weatherController.main.Visible == true then
weatherController.main.Visible = false
else
weatherController.main.Visible = true
end
end
weatherController.toggleWeatherUI.MouseButton1Click:Connect(clickedWeatherToggle)
timeBox.FocusLost:Connect(function(enteredTime)
print(timeBox)
end)
Module script;
local weatherController = game.StarterGui.weatherController
local timeBox = weatherController.main.timeOfDay
local timeOfDay2 = game.Lighting.TimeOfDay
local timeThing = {}
-- local enteredText = timeBox.Text
function timeThing:enteredTime()
local enteredText = timeBox.Text
tostring(enteredText)
if enteredText:find(":") and (":") then
print(enteredText)
enteredText = timeOfDay2
end
end
return timeThing
I’m fairly confident I’m going about this whole thing wrong, specifically the part where I am trying to get a variable from the module script (aka timeBox). yet it won’t register even tough I used require() and the function timeThing registers.
I just don’t know how I should go about this the proper way.
I thought that TimeOfDay’s formatting is nicer and more precise (which it kinda is), but honestly I think I might switch to ClockTime since it’s just easier to type and format.
Also, I’m just trying to do it for local player for now. Then after I get this working I’m gonna work on replication to other clients.
This fixed things up a little bit, so thank you for that suggestion! Last error I’m having now, is that the time of day still doesn’t set. Any help would be still greatly appreciated!
function timeThing:EnterTime(TimeBox)
local enteredText = timeBox.Text
if tonumber(enteredText) <= 24 then
game.Lightning.ClockTime = enteredText
else return
end
end
local timeThing = require(game.ReplicatedStorage.modules.timeThing)
local weatherController = script.Parent
local timeBox = weatherController.main.timeOfDay
function clickedWeatherToggle()
print("clicked")
weatherController.main.Visible = not weatherController.main.Visible
end
weatherController.toggleWeatherUI.MouseButton1Click:Connect(clickedWeatherToggle)
timeBox.FocusLost:Connect(function(enteredTime)
print(timeBox.Text)
end)
Yep, it’s local, I meant that it doesn’t work on either the client OR server. Apologies for the misunderstanding.
I really wonder what’s causing the time of day to not change?
Fixed.
Thanks for assistance @djk875! We ended up removing the modulescript as of 11/19/22, but I’ll update this post when we re-implement the modulescript for the localscript.
Personal comment from djk875;
“What I think was happened, is that as the FocusLost event was being fired it assigned the argument in enterTime(timeBox) as a boolean, and not as an instance of the timeBox. So I switched to using the variable for timeBox shown above, as it was already there” - djk875.
The working script;
local weatherController = script.Parent
local timeBox = weatherController.main.timeOfDay
function clickedWeatherToggle()
print("clicked")
weatherController.main.Visible = not weatherController.main.Visible
end
function enterTime()
game.Lighting.ClockTime = tonumber(timeBox.Text)
end
weatherController.toggleWeatherUI.MouseButton1Click:Connect(clickedWeatherToggle)
timeBox.FocusLost:Connect(enterTime)