Getting confusing error when attempting to call a function

So, I was trying to make a visible timer for a game… but I ran into a bit of a strange problem. On my last line of code, I get a strange error: Attempt to connect failed: Passed value is not a function

There are two weird things about this. One, the system functions a bit strangely before this, but that is a different issue, however, I get the error about 10 seconds in. Also, I have another line of code one line above the problem line which has no problems or errors. Does anyone know what’s happening?

The code:

wait(1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timer = game.Workspace.TimeCounter.Timer
local visibletimer = script.Parent.Parent.PlayerGui.TimeGUI.TG_Frame.TG_TimeLabel
local identifier = "wat"
local intermission = ReplicatedStorage:WaitForChild("Intermission")
local reset = ReplicatedStorage:WaitForChild("Reset")
local newserver = ReplicatedStorage:WaitForChild("NewServer")
local enoughplayers = false

timer.Changed:Connect(function()
	visibletimer.Text = identifier .. timer.Value
end)

intermission.OnClientEvent:Connect(function()
	enoughplayers = true
	identifier = "Intermission: "
end)

local function notenoughplayers()
	repeat
		visibletimer.Text = "Waiting for players."
		wait (0.75)
		visibletimer.Text = "Waiting for players.."
		wait (0.75)
		visibletimer.Text = "Waiting for players..."
		wait (0.75)
	until enoughplayers == true
end

reset.OnClientEvent:Connect(notenoughplayers())
newserver.OnClientEvent:Connect(notenoughplayers())

(BTW this is in a LocalScript located in a GUI inside of StarterGUI)

You don’t need to include those parenthesis when connecting the event, it should be something like this?

reset.OnClientEvent:Connect(notenoughplayers)
newserver.OnClientEvent:Connect(notenoughplayers)

That worked perfectly! Thanks for the help!

1 Like

also i want to note that in the variable visibletimer you say “script.Parent.Parent.PlayerGui” to get the player containing the player gui you can use LocalPlayer witch is in playerservice to get the local player. also you should use “WaitForChild()” on the PlayerGui since it may take time for the PlayerGui to load on the player.

I’ll admit, that’s better than the wait function that I have at the beginning as well. Thanks!