Event not firing with no errors in output

Hello everyone who is reading, I hope your day has been going well!
Recently, I’ve been trying to make it where the certain players have the ability to change the time of day. Everytime the player presses the SetButton, it would change to whatever ClockTime value the player put within the Time Textbox. However whenever the player presses the button and fires the event to the server nothing happens. I used a local script to call event from but it doesn’t fire at all but there are no errors in the output.

Any help is very appreciated!

Here’s where the script is:
image

Local Script:

local event = game.ReplicatedStorage.Events.ChangeTime

local player = game.Players.LocalPlayer
local button = script.Parent
local Time = button.Parent.Time

local function ChangeTime()
	event:FireServer(tonumber(Time.Text))
end

button.TouchTap:Connect(function()
	event:FireServer(tonumber(Time.Text))
end)
button.MouseButton1Click:Connect(function()
	event:FireServer(tonumber(Time.Text))
end)

Server Script:

local lighting = game.Lighting

local Changing = false

local Time = 0.01
local TimeSpeed = 0.0025

while wait(Time) do
	lighting.ClockTime = lighting.ClockTime + TimeSpeed
end

game.ReplicatedStorage.Events.ChangeTime.OnServerEvent:Connect(function(player, NewTime)
	lighting.ClockTime = NewTime
	print("ChangeTime Activated")
end)

Can you try this?

local event = game.ReplicatedStorage: WaitForChild ("Events").ChangeTime

the event might not be there when it’s looking for it.

I changed the event variables on both scripts and the event still isn’t being fired.

Have you added prints under button and sever side after event? And if only button prints try commenting out the while loop.

I have prints attached to the event and I had prints attached to the button but removed them after seeing the button works.

So is it the same without the while loop?

just receieved an error 15:33:37.275 Remote event invocation queue exhausted for ReplicatedStorage.Events.ChangeTime; did you forget to implement OnServerEvent? (16 events dropped) - Studio

This wouldn’t Exactly do anything, Everything is already loaded on the Server, WaitForChild would be used more with finding items on the Client as it takes time to download.

Or, it can be used as an alternative wait()

1 Like

Your Issue appears to be the while loop which halts the code until its broken, Since the loop is preventing a new Connection, the game will think there is no Connection for this RemoteEvent, try using task.spawn() or coroutine.create()/coroutine.wrap() to have it run alongside the main code:

task.spawn(function()
   while task.wait(Time) do
	   lighting.ClockTime = lighting.ClockTime + TimeSpeed
   end
end)

game.ReplicatedStorage.Events.ChangeTime.OnServerEvent:Connect(function(player, NewTime)
	lighting.ClockTime = NewTime
	print("ChangeTime Activated")
end)

Also, you can do Variable += Number instead of Variable = Variable + Number

coroutine.wrap(function()
    while task.wait(Time) do
        lighting.ClockTime += TimeSpeed
    end
end)()

This should make it so your loop doesn’t disrupt the code

1 Like

it worked! Thank you so much for the help everyone, I really appreciate it!

Here’s the new code for anyone who is interested.

local script:

local event = game.ReplicatedStorage.Events:WaitForChild("ChangeTime")

local player = game.Players.LocalPlayer
local button = script.Parent
local Time = button.Parent.Time

local function ChangeTime()
	event:FireServer(tonumber(Time.Text))
end

button.TouchTap:Connect(function()
	event:FireServer(tonumber(Time.Text))
end)

button.MouseButton1Click:Connect(function()
	event:FireServer(tonumber(Time.Text))
end)

server script:

local lighting = game.Lighting

local Changing = false

local Time = 0.01
local TimeSpeed = 0.0025

task.spawn(function()
	while task.wait(Time) do
		lighting.ClockTime = lighting.ClockTime + TimeSpeed
	end
end)

game.ReplicatedStorage.Events:WaitForChild("ChangeTime").OnServerEvent:Connect(function(player, NewTime)
	lighting.ClockTime = NewTime
	print("ChangeTime Activated")
end)

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