What am I doing wrong? Local script doesn't properly work with modulescript

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.

local timeBox = weatherController.main.timeOfDay.Text 

You set your variable to the inital text in the box and never updating the value

Try adding an else statement here, with a print. Might tell you something.

1 Like

How should I go about making it update?

Before I judge anything I have a quick question

Is “timeOfDay” a TextBox?

Yes, it is, here’s a screenshot of the explorer.

image

Why dont you use game.Lightning.ClockTime? Also, are you trying to change the time of day for all players or just the local player?

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.

In that case your setting your code up wrong, FocusLost is a event of TextBox, not “Text”

you should be doing this instead

weatherController.main.timeOfDay.FocusLost:Connect(function(enteredTime)
	print(weatherController.main.timeOfDay.Text)
end)

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

Not so sure if this works.

Also

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)

It works aside from changing the time of day inputted, on the client and server.

Oh i forgot that if you wanna make the daytime change locally, it must be a local script.

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?

Man, more developers really need to know this!

1 Like

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)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.