Lua Hook Help

I’m trying to make a ULX addon to give roles, but it won’t work. The detective is old code, and I want the role code to trigger when the round starts. I tried it on the traitor command, but it wont work. Error code:

Lua code:


local CATEGORY_NAME = "Britannia TTT"

function ulx.group(calling_ply)
calling_ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/britanniattt")]])
end

local group = ulx.command(CATEGORY_NAME, "ulx group", ulx.group, "!group", true)

group:help(" Shows link to our Steam Group." )
group:defaultAccess(ULib.ACCESS_ADMIN)

function ulx.traitor(calling_ply)
    hook.add("TTTBeginRound", calling_ply:UniqueID() .. "_traitor", function()
	if ply:GetRoleString() != "traitor" then
	calling_ply:SetRole(ROLE_TRAITOR)
    calling_ply:AddCredits(2))
	end
end
function ulx.detective(calling_ply)
calling_ply:SetRole(ROLE_DETECTIVE)
calling_ply:AddCredits(1)
end

local traitor = ulx.command(CATEGORY_NAME, "ulx traitor", ulx.traitor, "!traitor", true)

local detective = ulx.command(CATEGORY_NAME, "ulx detective", ulx.detective, "!detective", true)

traitor:help("Robi ciebie zdrajcą")
traitor:defaultAccess(ULib.ACCESS_ADMIN)

detective:help("Robi ciebie detektywem")
detective:defaultAccess(ULib.ACCESS_ADMIN)

[lua]local CATEGORY_NAME = “Britannia TTT”

function ulx.group(calling_ply)
calling_ply:SendLua([[gui.OpenURL(“http://steamcommunity.com/groups/britanniattt”)]])
end

local group = ulx.command(CATEGORY_NAME, “ulx group”, ulx.group, “!group”, true)

group:help(" Shows link to our Steam Group." )
group:defaultAccess(ULib.ACCESS_ADMIN)

function ulx.traitor(calling_ply)
hook.add(“TTTBeginRound”, calling_ply:UniqueID() … “_traitor”, function()
if ply:GetRoleString() != “traitor” then
calling_ply:SetRole(ROLE_TRAITOR)
calling_ply:AddCredits(2)
end
end)
end

function ulx.detective(calling_ply)
calling_ply:SetRole(ROLE_DETECTIVE)
calling_ply:AddCredits(1)
end

local traitor = ulx.command(CATEGORY_NAME, “ulx traitor”, ulx.traitor, “!traitor”, true)

local detective = ulx.command(CATEGORY_NAME, “ulx detective”, ulx.detective, “!detective”, true)

traitor:help(“Robi ciebie zdrajcą”)
traitor:defaultAccess(ULib.ACCESS_ADMIN)

detective:help(“Robi ciebie detektywem”)
detective:defaultAccess(ULib.ACCESS_ADMIN)
[/lua]

You had one too many )'s and missing an end for the hook.

edit: Cloudflare keeps thinking that code above is bad and keeps asking for captchas :v

Isn’t it supposed to be there to finish the “(” at hook.add( ?

Yes, but you were missing an end for the hook as you opened a function.

I’m pretty new to all the lua coding and this is my first hook. Now I tried to make it this way:


local CATEGORY_NAME = "Britannia TTT"

function ulx.group(calling_ply)
calling_ply:SendLua([[gui.OpenURL("http://steamcommunity.com/groups/britanniattt")]])
end

local group = ulx.command(CATEGORY_NAME, "ulx group", ulx.group, "!group", true)

group:help(" Shows link to our Steam Group." )
group:defaultAccess(ULib.ACCESS_ADMIN)

function ulx.traitor(calling_ply)
    hook.add("TTTBeginRound", calling_ply:UniqueID() .. "_traitor", function()end
	if ply:GetRoleString() != "traitor" then
	calling_ply:SetRole(ROLE_TRAITOR)
    calling_ply:AddCredits(2)
	end
end
function ulx.detective(calling_ply)
calling_ply:SetRole(ROLE_DETECTIVE)
calling_ply:AddCredits(1)
end

local traitor = ulx.command(CATEGORY_NAME, "ulx traitor", ulx.traitor, "!traitor", true)

local detective = ulx.command(CATEGORY_NAME, "ulx detective", ulx.detective, "!detective", true)

traitor:help("Robi ciebie zdrajcą")
traitor:defaultAccess(ULib.ACCESS_ADMIN)

detective:help("Robi ciebie detektywem")
detective:defaultAccess(ULib.ACCESS_ADMIN)

I get this error:

As he said, you are missing an end to close the third argument of the hook.Add function and a closing parenthesis to close the hook.Add function. Also, the name of the function is hook.Add, not hook.add. Capitalization matters.

I fixed it.
Thanks everyone for the help.