Help with random script error

Hello all. My server uses the following code to send maps to clients via the steam workshop.

maplist = {}

maplist["ttt_lost_temple_v2"] = "106527577"
maplist["ttt_dolls"] = "195227686"
maplist["ttt_clue"] = "192491456"
maplist["ttt_cruise"] = "186012196"
maplist["ttt_slender"] = "165026364"
maplist["ttt_68thway_brownie_b"] = "169893964"
maplist["ttt_bank_b3"] = "186008966"
maplist["ttt_crystalmaze"] = "188379418"
maplist["ttt_swimming_pool_v2"] = "188113109"
maplist["ttt_district_a5"] = "186843370"
maplist["ttt_office_b1"] = "186844385"
maplist["ttt_slender_v2"] = "108039266"
maplist["ttt_community_pool_revamped"] = "144575800"
maplist["ttt_fg_sexy_render_v6a"] = "204775675"
maplist["ttt_waterworld"] = "157420728"
maplist["ttt_community_bowling_v5a"] = "131667838"
maplist["ttt_bb_teenroom_b2"] = "141103402"
maplist["ttt_trappycottage_b2"] = "214511049"
maplist["ttt_scarisland_b1"] = "185635263"
maplist["ttt_clocktown_v1"] = "220740097"
maplist["ttt_bb_outpost57_b5"] = "124463722"
maplist["ttt_minecraft_mythic_b8"] = "200609954"
maplist["ttt_minecraftcity_v4"] = "186842624"
maplist["ttt_nuclear_power_b1"] = "131775216"
maplist["ttt_lttp_kakariko_a4"] = "118937144"
maplist["ttt_airbus_b3"] = "199933864"
maplist["ttt_aircraft_v1b"] = "154177743"
maplist["ttt_peachs_castle"] = "222770809"
maplist["ttt_chaser_v2"] = "109410344"
maplist["ttt_mcdonalds"] = "264839450"
maplist["ttt_ski_resort_a5_f1"] = "255827210"
maplist["ttt_rooftops_lost"] = "288523538"
maplist["ttt_castle_2011_v3_day"] = "284613981"
maplist["ttt_comancher_censored"] = "109144069"
maplist["ttt_forest_final"] = "147635981"
maplist["ttt_crummycradle_a4"] = "264864627"
maplist["ttt_plaza_b7"] = "137891506"
maplist["ttt_hairyhouse"] = "196720505"
maplist["ttt_datmap"] = "222957320"
maplist["ttt_maze_01"] = "382159417"

--add more maps here

local map = game.GetMap() -- Get's the current map name
local workshopid = maplist[map] 
-- Finds the workshop ID for the current map name from the table above

if( workshopid != nil )then
	--If the map is in the table above, add it through workshop
	print( "[WORKSHOP] Setting up maps. " " workshop ID: " ..workshopid )
	resource.AddWorkshop( workshopid )
	--If not, ) then hope the server has FastDL or the client has the map
	print( "[WORKSHOP] Not available for current map. Using FastDL instead hopefully..." )

I don’t really remember where I got this code, I just found it somewhere on the internet. But regardless, any time someone joins the server on any of the maps on that list, they get the following script error:

[ERROR] lua/autorun/maploader.lua:57: attempt to call field 'AddWorkshop' (a nil value)
  1. unknown - lua/autorun/maploader.lua:57

It still works fine and everything, so this isn’t really an urgent issue. It’s just an annoyance that I haven’t been able to figure out. If anyone can see what’s causing this script error, I’d greatly appreciate it.

Put it in lua/autorun/server/ because the resource.AddWorkshop() is a server side function. So called from client side it will give an error because there’s no such function there.

Aren’t those automatically added if the map addons are in the collection?

Uh, only if that’s a fairly recent addition. I’ve been running this server for over a year and only recently went on a crusade to remove all script errors. This was the last one. But anyway back when I first took the server no, this file was definitely necessary. Then again, I was adding many of the maps via .bsp file instead of through the workshop collection, so that may have been the problem there… Hm.

Anyway the problem is now fixed either way, so thanks Busan1. I actually thought I had the code inside an if SERVER than statement but I guess I didn’t notice it wasn’t there. Oh well. Thanks again.