Function isn't running

Okay. So, I have a function called Round_Start. It’s being include’d in my gamemode’s init.lua file.

However, it refuses to run.


function Round_Start()

	GAMEMODE:OnRoundStart()
	
	print( "func has run" )

end

Note that GAMEMODE:OnRoundStart is in another file, and is being include’d before this function is.

There’s no “func has run” in the console, and nothing that should happen in OnRoundStart is happening. Note that I’m calling this func in InitPostEntity. Why isn’t it running?

Try to print something in InitPostEntity if nothing is happening you did something wrong somewhere else.

Lets say your include isn’t loaded but init.lua is that would cause to error something like “Attempt to call a nil value”

So to me it sounds like your init.lua isn’t doing anything probably because of errors in the attempt to load it.

Best to look for errors in the console.

I’m not getting any errors.

Are you actually RUNNING it in any file? Just defining a function with that name wouldn’t automatically make it work…

Yep. I’m running Round_Start in InitPostEntity.

Can you post the code for this? (I’m not really sure what the problem is but maybe it’ll help)


function GM:InitPostEntity()

	Round_Start()

	FileCheck()

end

Round_Start isn’t running.

Just wondering (I’m probably wrong), but shouldn’t GAMEMODE be GM? Or, perhaps GM:InitPostEntity() should be GAMEMODE:InitPostEntity()?

You know what, in the Round_Start function I iterate over player.GetAll() and give weapons to them. I’m not getting the weapons when I join the game.

Because you’re overwriting the InitPostEntity function. Use hooks.

Okay, some testing has revealed that iterating over player.GetAll() in InitPostEntity doesn’t do anything, hence why my round-beginning code doesn’t work. What should I do in this case?

And no, timers won’t do anything either unless I set it to like 10 seconds(which delays the round starting beyond belief), is there any other hook I can use?

What? You didn’t even say you were using a hook anywhere in this sentence. The function GM:InitPostEntity isn’t a hook, you need to actually ADD a new hook…

Remove your GM:InitPostEntity function and…

Try this:



hook.Add( 'InitPostEntity', 'RoundStartTest', function()

	Round_Start()

	FileCheck()

end )


Look idk if you’re creating a gamemode because of the way you are using the commands, but please check the wiki first for these kinds of things.
You can use PlayerInitialSpawn, PlayerSpawn, and PlayerAuthed