Function name described by the script editor as "Unknown symbol"

So I am scripting a EXP giver, and i’m using FireClient() and OnClientEvent. But there is a problem were when the function is being called at the end of the script it says the function name is an Unknown symbol. I have checked spelling, and its correct

-- My code

local rp = game:GetService("ReplicatedStorage")
local event = rp:WaitForChild("Add5EXPGui")
event.OnClientEvent:Connect(function(clientEvent) 
	script.Parent.Main.Exp5.Visible = true
	wait(2)
	script.Parent.Main.Exp5.Visible = false
end)

event.OnClientEvent:Connect(clientEvent) -- this is the problematic line

You have no function named clientEvent. I think this is what you meant to do

local rp = game:GetService("ReplicatedStorage")
local event = rp:WaitForChild("Add5EXPGui")
local function clientEvent()
	script.Parent.Main.Exp5.Visible = true
	wait(2)
	script.Parent.Main.Exp5.Visible = false
end

event.OnClientEvent:Connect(clientEvent)

First of all, you have this line:

event.OnClientEvent:Connect(function(clientEvent) 

Secondly you call Connect a second time here:

event.OnClientEvent:Connect(clientEvent) -- this is the problematic line

I don’t really understand what you’re trying to do there with “clientEvent”. Did you mistype the script, because, I see nothing that would produce an “unknown symbol” error if you typed it correctly.

Are you trying to define your function like this?:

event.OnClientEvent:Connect(function clientEvent() 

If so, you can’t do this, because its sort of like doing this, which would be invalid:

event.OnClientEvent:Connect(clientEvent = function()

Instead, if you want your function to have a name you should do this:

function clientEvent()
	-- Stuff
end

event.OnClientEvent:Connect(clientEvent)

Otherwise, you can do this to create an anonymous (unnamed) function:

event.OnClientEvent:Connect(function()
	-- Stuff
end)

You can’t both name a function, and pass it as an argument at the same time, you can only do either or.

(Also, tip, you can also locally define functions like this)

local function functionName()

end

-- Which is the same as
local functionName = function()

end
1 Like

You don’t need the second :Connect() statement. You already declared an anonymous function in the first one.