Sharing variables across server and client

I originally posted this on the dark rp forum, but this one looks a bit more active and I figure this isn’t a problem specific to dark rp, but more related to how the lua’s work

I’m fairly new to lua and I’m not sure where to go from here. I have an sv_updateAnnouncement file with a timer in it. It’s set up such that it will update a string when it is triggered. However, I want that string to display on a hud element on the users screen. I thought that by defining the string to be used in an sh_init file, it would be shared between the cl_hud file and the sv_updateAnnouncement file, but at the moment, the text is not being drawn. Here is some of the code I have in them

teams= {
team1 = “team1”,
team2 = “team2”,
team3 = “team3”,
team4 = “team4”

event= {}

event[1] = “event1”
event[2] = “event2”
event[3] = “event3”
event[4] = “event4”
event[5] = “event5’”
event[6] = “event6”

totalEvent = 6

teamEvent= {}
teamEvent[teams.team1] = “”
teamEvent[teams.team2] = “”
teamEvent[teams.team3] = “”
teamEvent[teams.team4] = “”


local eventTime = 30

timer.Create( “Event”, eventTime, 0, function()
if (true) then
for k,v in pairs(player.GetAll()) do
DarkRP.notify(v,0,4,“New Event”)
local newEvent1 = math.random(1,totalEvent)
local newEvent2 = math.random(1,totalEvent)
while (newEvent1== newEvent2) do
newEvent2= math.random(1,totalEvent)

teamEvent[teams.team1] = event[newEvent1]
teamEvent[teams.team2] = event[newEvent2]
teamEvent[teams.team3] = event[newEvent1]
teamEvent[teams.team4] = event[newEvent2]


local function HudClass()
draw.RoundedBox(6, HUD.PosX+5, HUD.PosY+HUD.Height-24-5, HUD.Width-10, 24, Color(0, 0, 0, 200))
local currentJob = LocalPlayer():getDarkRPVar(“job”)
local teamMessage = “”

if currentJob == “team1” then
teamMessage = teamEvent[teams.team1]

elseif currentJob == “team2” then
teamMessage = teamEvent[teams.team2]

elseif currentJob == “team3” then
teamMessage = teamEvent[teams.team3]

elseif currentJob == “team4” then
teamMessage = teamEvent[teams.team4]

teamMessage = "DEBUG: current class = " … currentJob

draw.DrawText(teamMessage, “TCBFont”, HUD.PosX+HUD.Width/2+1, HUD.PosY+HUD.Height-24-5+3+1, Color(0, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.DrawText(teamMessage, “TCBFont”, HUD.PosX+HUD.Width/2, HUD.PosY+HUD.Height-24-5+3, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

So I define all of my tables in the sh file, I update them in the sv timer, and then I display them in the cl hud, but at the moment, the cl hud is displaying an empty string. What am I doing wrong here?

Not really sure how globals work in lua, but all 3 files are in the same folder

EDIT: currently, the hud shape is being drawn correctly, and the debug message appears as it should, but the actual text i need is not shared across the files

You could try to use something like

Ooh that actually might work out much better, that way im doing the conditional in the timer instead of on the ui rendering, and all I have to do in the rendering is pull the nw string for the player in question, I’ll try that out

EDIT: that worked beautifully, thank you