Addon works only in Singleplayer.

I am currently developing a small little addon for the TTT Gamemode.
The thing is, it works in singleplayer but not in multiplayer.
What could be causing this?

Did you AddCSLuaFile the clientside files?

I have one single File located in the entities folder of TTT.
It begins with the AddCSLuaFile() command…

Can you post the contents of the file?


AddCSLuaFile()

local surface = surface
local pairs = pairs
local math = math
local abs = math.abs
local roundinprog = true

hook.Add("Initialize", "InitializeCustomTTTItems", function() -- delay until gamemode is loaded
	if !EquipmentItems then return end -- not TTT
	
	EQUIP_TBH = 8

	for role,items in pairs(EquipmentItems) do
			for _,item in pairs(items) do
				if item.id > EQUIP_TBH then -- if the ID you picked already exists increase it
					EQUIP_TBH = item.id*2
				end
			end
		end

	local item = {
		id = EQUIP_TBH,
		name = "Traitor Button Hack",
		desc = "This Items allows you to hack into the Traitor Network, 
 and enables you to use the Traitor Buttons.",
		type = "item_passive",
		material = "vgui/ttt/tbut_hand_filled",
		loadout = false
	}

	table.insert(EquipmentItems[ROLE_DETECTIVE], item)
end)

hook.Add("TTTOrderedEquipment", "TTTAddAttachment", function(ply, equipment, is_item)
   if equipment == EQUIP_TBH then
      TBHUD:Draw(ply)
   end
end)

gameevent.Listen("T_Use_TButton")
hook.Add("T_Use_TButton", "revealPos" , function(plysend,ent)
   local TPos = plysend:GetPos()
   local TBPos = ent:GetPos()
   local recievers = {}
   for k, v in pairs(player.GetAll()) do
      if v:HasEquipmentItem(EQUIP_TBH) then
         recievers[k] = v
      end
   end
   if receivers != nil then
      for k, v in pairs(receivers) do
         util.AddNetworkString("TTT_DrawTraitorPos")
         net.Start("TTT_DrawTraitorPos") net.WriteVector(TPos) net.WriteVector(TBPos) net.Send(receivers[k])
      end
   end
end)

hook.Add("TTTEndRound", "reset_equipment", function(result)
   roundinprog = false
end)

TBHUD = {}
TBHUD.buttons = {}
TBHUD.buttons_count = 0

TBHUD.focus_ent = nil
TBHUD.focus_stick = 0

function TBHUD:Clear()
   self.buttons = {}
   self.buttons_count = 0

   self.focus_ent = nil
   self.focus_stick = 0
end

function TBHUD:CacheEnts()
   if IsValid(LocalPlayer()) and (LocalPlayer():HasEquipmentItem(EQUIP_TBH) or LocalPlayer():IsActiveTraitor()) then
      self.buttons = {}
      for _, ent in pairs(ents.FindByClass("ttt_traitor_button")) do
         if IsValid(ent) then
            self.buttons[ent:EntIndex()] = ent
         end
      end
   else
      self.buttons = {}
   end

   self.buttons_count = table.Count(self.buttons)
end

function TBHUD:PlayerIsFocused()
   return IsValid(LocalPlayer()) and (LocalPlayer():HasEquipmentItem(EQUIP_TBH) or LocalPlayer():IsActiveTraitor()) and IsValid(self.focus_ent) and roundinprog
end

function TBHUD:UseFocused()
   if IsValid(self.focus_ent) and self.focus_stick >= CurTime() then
   
      RunConsoleCommand("ttt_use_tbutton", tostring(self.focus_ent:EntIndex()))
     
      self.focus_ent = nil
      return true
   else
      return false
   end
end

local function Use(ply, cmd, args)
   if #args != 1 then return end
   local idx = tonumber(args[1])
   if idx then
      local ent = Entity(idx)
      if IsValid(ply) and (ply:IsActiveTraitor() or (ply:HasEquipmentItem(EQUIP_TBH) and ply:GetCredits() > 0)) then
         if IsValid(ent) and ent.TraitorUse then
            if not (IsValid(ply) and (ply:IsActiveTraitor() or ply:HasEquipmentItem(EQUIP_TBH))) then return false end
            if not ent:IsUsable() then return false end
            if ent:GetPos():Distance(ply:GetPos()) > ent:GetUsableRange() then return false end
               net.Start("TTT_ConfirmUseTButton") net.Send(ply)

               -- send output to all entities linked to us
               ent:TriggerOutput("OnPressed", ply)
			   if ply:HasEquipmentItem(EQUIP_TBH) and not ply:IsActiveTraitor() then
			      ply:SubtractCredits(1)
               end
			   if ply:IsActiveTraitor() then
			      hook.Call("T_Use_TButton", nil, ply, ent)
			   end
			   
               if ent.RemoveOnPress then
                  ent:SetLocked(true)
                  ent:Remove()
               else
                  -- lock ourselves until we should be usable again
                  ent:SetNextUseTime(CurTime() + ent:GetDelay())
               end
			end
            return true
         end
		 if ply:HasEquipmentItem(EQUIP_TBH) and ply:GetCredits() == 0 then
            util.AddNetworkString("TTT_DenyUseTButton")
		    net.Start("TTT_DenyUseTButton") net.Send(ply)
		 end
      end
end
concommand.Remove("ttt_use_tbutton")
concommand.Add("ttt_use_tbutton", Use)

local confirm_sound = Sound("buttons/button24.wav")
function TBHUD.ReceiveUseConfirm()
   surface.PlaySound(confirm_sound)

   TBHUD:CacheEnts()
end
net.Receive("TTT_ConfirmUseTButton", TBHUD.ReceiveUseConfirm)

local noCredits = Sound("buttons/button11.wav")
function TBHUD.ReceiveUseDeny()
   surface.PlaySound(noCredits)

   TBHUD:CacheEnts()
end
net.Receive("TTT_DenyUseTButton", TBHUD.ReceiveUseDeny)

local healsound = Sound("items/medshot4.wav")
local failsound = Sound("items/medshotno1.wav")
function TBHUD.DrawPos()
   surface.PlaySound(healsound)
   surface.PlaySound(failsound)
   local scrposTB = net.ReadVector():ToScreen()
   local scrposT = net.ReadVector():ToScreen()
   if not (IsOffScreen(scrposTB) and IsOffScreen(scrposT))then
      surface.DrawLine(scrposTB.x, scrposTB.y, scrposT.x, scrposT.y)
   end
end
net.Receive("TTT_DrawTraitorPos", TBHUD.DrawPos)

local size = 32
local mid  = size / 2
local focus_range = 25

local GetTranslation = LANG.GetTranslation
local GetPTranslation = LANG.GetParamTranslation
function TBHUD:Draw(client)
   if self.buttons_count ~= 0 and roundinprog then
      surface.SetTexture(surface.GetTextureID("vgui/ttt/tbut_hand_line"))

      -- we're doing slowish distance computation here, so lots of probably
      -- ineffective micro-optimization
      local plypos = client:GetPos()
      local midscreen_x = ScrW() / 2
      local midscreen_y = ScrH() / 2
      local pos, scrpos, d
      local focus_ent = nil
      local focus_d, focus_scrpos_x, focus_scrpos_y = 0, midscreen_x, midscreen_y

      -- draw icon on HUD for every button within range
      for k, but in pairs(self.buttons) do
         if IsValid(but) and but.IsUsable then
            pos = but:GetPos()
            scrpos = pos:ToScreen()

            if (not IsOffScreen(scrpos)) and but:IsUsable() then
               d = pos - plypos
               d = d:DotProduct(d) / (but:GetUsableRange() ^ 2)
               -- draw if this button is within range, with alpha based on distance
               if d < 1 then
                  surface.SetDrawColor(255, 255, 255, 200 * (1 - d))
                  surface.DrawTexturedRect(scrpos.x - mid, scrpos.y - mid, size, size)

                  if d > focus_d then
                     local x = abs(scrpos.x - midscreen_x)
                     local y = abs(scrpos.y - midscreen_y)
                     if (x < focus_range and y < focus_range and
                         x < focus_scrpos_x and y < focus_scrpos_y) then

                        -- avoid constantly switching focus every frame causing
                        -- 2+ buttons to appear in focus, instead "stick" to one
                        -- ent for a very short time to ensure consistency
                        if self.focus_stick < CurTime() or but == self.focus_ent then
                           focus_ent = but
                        end
                     end
                  end
               end
            end
         end

         -- draw extra graphics and information for button when it's in-focus
         if IsValid(focus_ent) then
            self.focus_ent = focus_ent
            self.focus_stick = CurTime() + 0.1

            local scrpos = focus_ent:GetPos():ToScreen()

            local sz = 16

            -- redraw in-focus version of icon
            surface.SetTexture(surface.GetTextureID("vgui/ttt/tbut_hand_filled"))
            surface.SetDrawColor(255, 255, 255, 200)
            surface.DrawTexturedRect(scrpos.x - mid, scrpos.y - mid, size, size)

            -- description
            surface.SetTextColor(255, 50, 50, 255)
            surface.SetFont("TabLarge")

            local x = scrpos.x + sz + 10
            local y = scrpos.y - sz - 3
            surface.SetTextPos(x, y)
            surface.DrawText(focus_ent:GetDescription())

            y = y + 12
            surface.SetTextPos(x, y)
            if focus_ent:GetDelay() < 0 then
               surface.DrawText(GetTranslation("tbut_single"))
            elseif focus_ent:GetDelay() == 0 then
               surface.DrawText(GetTranslation("tbut_reuse"))
            else
               surface.DrawText(GetPTranslation("tbut_retime", {num = focus_ent:GetDelay()}))
            end

            y = y + 12
            surface.SetTextPos(x, y)
            surface.DrawText(GetPTranslation("tbut_help", {key = Key("+use", "USE")}))
         end
      end
   end
end

here you go…

That isn’t an entity and you “have one single File located in the entities folder of TTT”?

It needs to be in an addon or gamemode or /lua/autorun