• I have to save the .lua file before it runs
    14 replies, posted
I have no idea how to explain this, but I hope you understand what my question is: My code wont run in-game until I save the .lua file, I have to save the lua file each time the server starts up for it to run. Know a fix? Thanks in advance. (Note: Yes, I know that this is basic Lua knowledge, but I'm still very new.)
Can you show us the file?
Yeah sure, its simple, but I'd like to get it working before i add to it hook.Add("playerWalletChanged","HomelessCheck",local function(ply, given, wallet) if wallet + given >= 100 then ply:changeTeam(TEAM_CITIZEN, true) elseif wallet + given <= 100 then player.changeTeam(TEAM_HOBO, true) end end end)
You have an extra end there, not sure why it works after you reload, but you obviously should see a lua error when trying to load that file
Sorry, my error, I accedentally pressed CRTL+D before snipping it XD, thats not the problem. Its also not giving errors, It just won't load up until I go into the file and save it.
If I'm understanding correctly, your code doesn't run until you make a small change and re-save the file while the server is running? That is, it doesn't run correctly on startup? Saving the file triggers auto-refresh, which will re-execute the file---but since global variables can change over time, the context in which the code is run can be different. Given (my assumption) that it's not working on startup, you might be referencing variables that might not exist at that time, such as GAMEMODE. Search your server console for errors (use "lua_log_sv 1" to write a log file, if necessary).
XD
that is a cool idea
lol XD
where is the file, what folder is it in?
garrysmod/addons/job_npc/lua/autorun
is there a lua error at startup? i found that delaying the loading of a file's content can fix some lua errors local loaded=loaded or GAMEMODE and GAMEMODE.Config or player.GetAll()[1] local function init() --any code that you want to have delayed until after the gamemode has loaded end hook.Add("Initialize","some unique name",init)--this hook will call the function when the --gamemode loads if loaded then init() end--if we reload the file after darkrp has loadded or if there are players on the server, the function will be called
No there aren't
Are you sure it’s supposed to work? At one point you have player.changeTeam instead of player:changeTeam
The code in the actual server is a bit different, but I can reassure you it isn't the code, considering this happens to every script I've made, error or without error, Its not the code's fault, its the servers/and or file's fault, For the last time; IT RETURNS NO ERRORS.
Sorry, you need to Log In to post a reply to this thread.