LUA Help

Hello, I need help with a script that I am running. It’s an entity and what it is supposed to do is every so often (lets say maybe every 3 minutes) it will attempt to spawn an entity right next to it. There will be multiple entities it will attempt to spawn but the chance of its spawn depends on the rarity of the other entity it is trying to spawn. I get errors about the timer and it only runs the spawn function right when the entity is spawned from the q menu.



AddCSLuaFile("shared.lua")
include('shared.lua')

local LocalPos

function ENT:SpawnFunction( ply, tr )

		
 	if ( !tr.Hit ) then return end 
 	 
 	local SpawnPos = tr.HitPos + tr.HitNormal * 10 - Vector(0,0,1)
 	 
	local vec = ply:GetAimVector():Angle()
	local newAng = Angle(0,vec.y,0)
 	local ent = ents.Create( "prop_thumper" )
	ent:SetPos( SpawnPos ) 
	ent:SetAngles(newAng)
 	ent:Spawn()
 	ent:Activate() 
	ent:GetLocalPos()
	LocalPos = ent:GetLocalPos() //saves the entity's position to a variable
 	ent.Owner = ply
	DoFunction(self) // runs function
	
	return ent 
end

DoFunction = function(ent)
ent:RunFunction()
end



function ENT:RunFunction()
		if math.random(1, 2) == 1 then
		local ent=ents.Create("blah")
		ent:SetPos(Vector( LocalPos.x + 30, LocalPos.y + 30, LocalPos.z + 30 ))
		ent:Spawn()
		end
		if math.random(1, 100) == 1 then
		local ent=ents.Create("blah1")
		ent:SetPos(Vector( LocalPos.x + 30, LocalPos.y + 30, LocalPos.z + 30 ))
		ent:Spawn()
		end
		if math.random(1, 400) == 1 then
		local ent=ents.Create("blah2")
		ent:SetPos(Vector( LocalPos.x + 30, LocalPos.y + 30, LocalPos.z + 30 ))
		ent:Spawn()
		end // and so on
		

		
end
timer.Simple( 180, function() ent:RunFunction() end )