Attempt to index function with 'onclientevent'

Hello! I’m having trouble with the error message written in the title. I have tried looking up the error message to no success but am hopeful someone could point me in the right direction here.

This is my code (local script in the starterplayerscripts)

local player = game.Players.LocalPlayer
local Gui = player:WaitForChild("PlayerGui")
local timerGui = Gui:WaitForChild("TimerGui")
local textLabel = timerGui:WaitForChild("TextLabel")
local repStorage = game:GetService("ReplicatedStorage")
local timerEvent = repStorage:WaitForChild("Timer")

local function timer(currentTime, message)
	Gui.Text = (message..currentTime)
end

timer.OnClientEvent:Connect(timer) --this is where the problem is

Thanks!

You never referenced the timer variable and there’s also a function called timer.

1 Like

OnClientEvent should be used in a remote event, not in a function.

local player = game.Players.LocalPlayer
local Gui = player:WaitForChild("PlayerGui")
local timerGui = Gui:WaitForChild("TimerGui")
local textLabel = timerGui:WaitForChild("TextLabel")
local repStorage = game:GetService("ReplicatedStorage")
local timerEvent = repStorage:WaitForChild("Timer")

local function timer(currentTime, message)
	Gui.Text = (message..currentTime)
end

timerEvent.OnClientEvent:Connect(timer)
1 Like

Thank you! I feel stupid after this lol I really am just not the best scripter. I got it working fine now and doing what I want.